Functions
toArray
toArray(@StreamCapable text: String): Array<String>
Transform a string into an array of characteres, splitting every character of the string.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
text |
The string to transform |
Example
This example shows how toArray
behaves under different inputs.
Source
1
2
3
4
5
6
7
8
%dw 2.0
import toString from dw::util::Coercions
output application/json
---
{
a: toArray(""),
b: toArray("hola"),
}
Output
1
2
3
4
{
"a": [],
"b": ["h", "o", "l", "a"],
}
toBinary
toBinary(str: String, encoding: String): Binary
Transforms a String into a Binary using the given encoding
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
str |
|
encoding |
Example
This example shows how the toBinary
behaves under different inputs.
Source
1
2
3
4
5
6
7
%dw 2.0
import toBinary from dw::util::Coercions
output application/dw
---
{
a: toBinary("DW Binary", "UTF-32"),
}
Output
1
toBoolean
toBoolean(str: String): Boolean
Transform a String into a Boolean
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
str |
The string to be transformed |
Example
This example shows how the toBoolean
behaves under different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
output application/json
import toBoolean from dw::util::Coercions
---
{
a: toBoolean("true"),
b: toBoolean("false"),
c: toBoolean("FALSE"),
d: toBoolean("TrUe"),
}
Output
1
2
3
4
5
6
{
"a": true,
"b": false,
"c": false,
"d": true
}
toDate
toDate(str: String, format: String | Null = null, locale: String | Null = null): Date
Transforms a String into a Date using the given format
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
str |
The string to transform |
format |
The format to be used |
locale |
The locale of the format |
Example
This example shows how the toDate
behaves under different inputs.
Source
1
2
3
4
5
6
7
8
9
%dw 2.0
import toDate from dw::util::Coercions
output application/dw
---
{
a: toDate("2015-10-01"),
b: toDate("2003/10/01","yyyy/MM/dd")
}
Output
1
2
3
4
{
a: |2015-10-01|,
b: |2003-10-01| as Date {format: "yyyy/MM/dd"}
}
toDateTime
toDateTime(number: Number, unit: MillisOrSecs | Null = null): DateTime
Transform the given number into a DateTime using the given unit :"milliseconds" or "seconds"
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
number |
The number of millis or secs |
unit |
The unit if null "seconds" is the default |
Example
This example shows how the toDateTime
behaves under different inputs.
Source
1
2
3
4
5
6
7
8
9
%dw 2.0
output application/dw
import toDateTime from dw::util::Coercions
---
{
fromEpoch: toDateTime(1443743879),
fromMillis: toDateTime(1443743879000, "milliseconds"),
}
Output
1
2
3
4
{
fromEpoch: |2015-10-01T23:57:59Z|,
fromMillis: |2015-10-01T23:57:59Z|
}
toDateTime(str: String, format: String | Null = null, locale: String | Null = null): DateTime
Transforms a String into a DateTime using the given format
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
str |
The string to transform |
format |
The format to be used |
locale |
The locale of the format |
Example
This example shows how the toDateTime
behaves under different inputs.
Source
1
2
3
4
5
6
7
8
%dw 2.0
import toDateTime from dw::util::Coercions
output application/dw
---
{
a: toDateTime("2015-10-01T23:57:59Z"),
b: toDateTime("2003-10-01 23:57:59Z","yyyy-MM-dd HH:mm:ssz"),
}
Output
1
2
3
4
{
a: |2015-10-01T23:57:59Z|,
b: |2003-10-01T23:57:59Z| as DateTime {format: "yyyy-MM-dd HH:mm:ssz"},
}
toLocalDateTime
toLocalDateTime(str: String, format: String | Null = null, locale: String | Null = null): LocalDateTime
Transforms a String into a LocalDateTime using the given format
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
str |
The string to transform |
format |
The format to be used |
locale |
The locale of the format |
Example
This example shows how the toLocalDateTime
behaves under different inputs.
Source
1
2
3
4
5
6
7
8
9
%dw 2.0
import toLocalDateTime from dw::util::Coercions
output application/dw
---
{
a: toLocalDateTime("2015-10-01T23:57:59"),
b: toLocalDateTime("2003-10-01 23:57:59","yyyy-MM-dd HH:mm:ss")
}
Output
1
2
3
4
{
a: |2015-10-01T23:57:59|,
b: |2003-10-01T23:57:59| as LocalDateTime {format: "yyyy-MM-dd HH:mm:ss"}
}
toLocalTime
toLocalTime(str: String, format: String | Null = null, locale: String | Null = null): LocalTime
Transforms a String into a LocalTime using the given format
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
str |
The string to transform |
format |
The format to be used |
locale |
The locale of the format |
Example
This example shows how the toLocalTime
behaves under different inputs.
Source
1
2
3
4
5
6
7
%dw 2.0
import toLocalTime from dw::util::Coercions
output application/dw
---
{
a: toLocalTime("23:57:59"),
}
Output
1
2
3
{
a: |23:57:59|
}
toNumber
toNumber(dateTime: DateTime, unit: MillisOrSecs | Null = null): Number
Transforms a DateTime into a the Number of seconds or milliseconds depending in the specified unit.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
dateTime |
The datetime to be used |
unit |
The unit ("milliseconds" |
Example
This example shows how the toNumber
behaves under different inputs.
Source
1
2
3
4
5
6
7
8
%dw 2.0
import toNumber from dw::util::Coercions
output application/json
---
{
epoch: toNumber(|2015-10-01T23:57:59Z|),
millis: toNumber(|2015-10-01T23:57:59Z|, "milliseconds"),
}
Output
1
2
3
4
{
epoch: 1443743879,
millis: 1443743879000
}
toNumber(period: Period, unit: PeriodUnits | Null = null): Number
Transforms the given Period into a Number using the specified unit : "hours", "minutes" , "seconds" , "milliseconds" or "nanos"
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
period |
The period to be converted |
unit |
The unit to be used |
Example
This example shows how the toNumber
behaves under different inputs.
Source
1
2
3
4
5
6
7
%dw 2.0
import toNumber from dw::util::Coercions
output application/json
---
{
toSeconds: toNumber(|PT1H10M|, "seconds")
}
Output
1
2
3
{
"toSeconds": 4200
}
toNumber(value: String | Key, format: String | Null = null, locale: String | Null = null): Number
Transforms the specified String into a Number.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
value |
|
format |
|
locale |
Example
This example shows how the toNumber
behaves under different inputs.
Source
1
2
3
4
5
6
7
8
9
%dw 2.0
import toNumber from dw::util::Coercions
output application/json
---
{
"default": toNumber("1.0"),
withFormat: toNumber("0.005",".00"),
withLocale: toNumber("0,035","#.##","ES"),
}
Output
1
2
3
4
5
{
"default": 1.0,
"withFormat": 0.005,
"withLocale": 0.035
}
toPeriod
toPeriod(str: String): Period
Transform a String into a Period
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
str |
The string to be transformed |
Example
This example shows how the toPeriod
behaves under different inputs.
Source
1
2
3
4
5
6
7
8
%dw 2.0
import toPeriod from dw::util::Coercions
output application/dw
---
{
a: toPeriod("P1D"),
b: toPeriod("PT1H1M"),
}
Output
1
2
3
4
{
a: |P1D|,
b: |PT1H1M|
}
toRegex
toRegex(str: String): Regex
Transforms a String into a Regex
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
str |
The string to be transformed |
Example
This example shows how the toRegex
behaves under different inputs.
Source
1
2
3
4
5
6
7
8
%dw 2.0
output application/dw
import toRegex from dw::util::Coercions
---
{
a: toRegex("a-Z"),
b: toRegex("0-9+")
}
Output
1
2
3
4
{
a: /a-Z/,
b: /0-9+/
}
toString
toString(number: Number, format: String | Null = null, locale: String | Null = null, roundMode: RoundingMode | Null = null): String
Formats a Number and return a String with the result. A Pattern can be used in order to specify how the number needs to be formatted.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
number |
The number to be formatted |
format |
The format to be used |
locale |
The locale |
roundMode |
"UP" or "DOWN" or "CEILING" or "FLOOR" or "HALF_UP" or "HALF_DOWN" or "HALF_EVEN" |
Example
This example shows how the toString
behaves under different inputs.
Source
1
2
3
4
5
6
7
8
9
10
11
%dw 2.0
import toString from dw::util::Coercions
output application/json
---
{
a: toString(1.0),
b: toString(0.005,".00"),
c: toString(0.035,"#.##","ES"),
d: toString(0.005,"#.##","ES","HALF_EVEN"),
e: toString(0.035,"#.00",null,"HALF_EVEN"),
}
Output
1
2
3
4
5
6
7
{
"a": "1",
"b": ".01",
"c": "0,04",
"d": "0",
"e": ".04"
}
toString(date: Date | DateTime | LocalDateTime | LocalTime | Time, format: String | Null = null, locale: String | Null = null): String
Formats a Date DateTime Time into a String.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
date |
The date to be formatted |
format |
The format to be used to format the date. If null no format will be used |
locale |
The locale to be used. If null no locale will be used |
Example
This example shows how the toString
behaves under different inputs.
Source
1
2
3
4
5
6
7
8
9
10
11
%dw 2.0
import toString from dw::util::Coercions
output application/json
---
{
a: toString(|2015-10-01T23:57:59|),
b: toString(|2003-10-01T23:57:59|, "yyyy-MM-dd HH:mm:ss a"),
c: toString(|2003-10-01|, "yyyy/MM/dd"),
d: toString(|23:57:59|, "HH-mm-ss"),
e: toString(|2003-10-01T23:57:59|, "yyyy-MM-dd HH:mm:ss a", "ES"),
}
Output
1
2
3
4
5
6
7
{
"a": "2015-10-01T23:57:59",
"b": "2003-10-01 23:57:59 PM",
"c": "2003/10/01",
"d": "23-57-59",
"e": "2003-10-01 23:57:59 PM"
}
toString(binary: Binary, encoding: String): String
Transforms a Binary data into a String using the given encoding
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
binary |
The binary data |
encoding |
The encoding to be used |
Example
This example shows how the toString
behaves under different inputs.
Source
1
2
3
4
5
6
7
%dw 2.0
output application/json
var binaryData= "DW Test" as Binary {encoding: "UTF-32"}
---
{
a: toString(binaryData, "UTF-32"),
}
Output
1
2
3
{
"a": "DW Test"
}
toString(data: TimeZone | Uri | Boolean | Period | Regex | Key): String
Transform the value (TimeZone | Uri | Boolean| Period| Regex| Key) into the String representation
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
data |
The data to be transformed |
Example
This example shows how the toString
behaves under different inputs.
Source
1
2
3
4
5
6
7
8
9
%dw 2.0
output application/json
---
{
a: toString(|Z|),
b: toString(true),
c: toString(|P1D|),
d: toString(/a-Z/),
}
Output
1
2
3
4
5
6
{
"a": "Z",
"b": "true",
"c": "P1D",
"d": "a-Z"
}
toString(arr: Array<String>): String
Transform an array of characters into a String, by joining them.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
arr |
The array to transform |
Example
This example shows how toString
behaves under different inputs.
Source
1
2
3
4
5
6
7
8
%dw 2.0
import toString from dw::util::Coercions
output application/json
---
{
a: toString([]),
b: toString(["h", "o", "l", "a"]),
}
Output
1
2
3
4
{
"a": "",
"b": "hola",
}
toTime
toTime(str: String, format: String | Null = null, locale: String | Null = null): Time
Transforms a String into a Time using the given format
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
str |
The string to transform |
format |
The format to be used |
locale |
The locale of the format |
Example
This example shows how the toTime
behaves under different inputs.
Source
1
2
3
4
5
6
7
%dw 2.0
import toTime from dw::util::Coercions
output application/dw
---
{
a: toTime("23:57:59Z"),
}
Output
1
2
3
{
a: |23:57:59Z|
}
toTimeZone
toTimeZone(str: String): TimeZone
Transform a String into a TimeZone
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
str |
The string to be transformed |
Example
This example shows how the toBoolean
behaves under different inputs.
Source
1
2
3
4
5
6
7
8
9
%dw 2.0
output application/dw
import toTimeZone from dw::util::Coercions
---
{
a: toTimeZone("-03:00"),
b: toTimeZone("Z"),
c: toTimeZone("America/Argentina/Buenos_Aires"),
}
Output
1
2
3
4
5
{
a: |-03:00|,
b: |Z|,
c: |America/Argentina/Buenos_Aires|
}
toUri
toUri(str: String): Uri
Transforms a String into a URI
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
str |
The String to be transformed |
Example
This example shows how the toUri
behaves under different inputs.
Source
1
2
3
4
5
6
7
%dw 2.0
output application/json
import toUri from dw::util::Coercions
---
{
a: toUri("http://google.com")
}
Output
1
2
3
{
a: "http://google.com"
}
Types
MillisOrSecs
1
"milliseconds" | "seconds"
PeriodUnits
1
"hours" | "minutes" | "seconds" | "milliseconds" | "nanos"
RoundingMode
1
"UP" | "DOWN" | "CEILING" | "FLOOR" | "HALF_UP" | "HALF_DOWN" | "HALF_EVEN"