toBoolean

toBoolean(str: String): Boolean

Transform a String value into a Boolean value.

Introduced in DataWeave version 2.4.0.

Parameters

Name Description

str

The String value to transform into a Boolean value.

Example

This example shows how toBoolean behaves with different inputs.

Source

%dw 2.0
import * from dw::util::Coercions
output application/json
---
{
  a: toBoolean("true"),
  b: toBoolean("false"),
  c: toBoolean("FALSE"),
  d: toBoolean("TrUe")
}

Output

{
  "a": true,
  "b": false,
  "c": false,
  "d": true
}

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub