Contact Us 1-800-596-4880

++

DataWeave 2.1 is compatible with Mule 4.1. Standard Support for Mule 4.1 ended on November 2, 2020, and this version of Mule will reach its End of Life on November 2, 2022, when Extended Support ends.

Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted.

MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements.

++(Array<S>, Array<T>): Array<S | T>

Concatenates the elements of two lists (arrays) into a new list.

If the two arrays contain different types of elements, the resulting array is all of S type elements of Array<S> followed by all the T type elements of Array<T>. Either of the arrays can also have mixed-type elements. Note that the arrays can contain any supported data type.

Parameters

Name Description

source

The source list (an `Array).

with

The list to concatenate with the source list.

Example

The example concatenates an Array<Number> with an Array<String>.

Source

%dw 2.0
output application/json
---
{
  "result" : [0, 1, 2] ++ ["a", "b", "c"]
}

Output

{
  "result": [0, 1, 2, "a", "b", "c"]
}

Example

Source

%dw 2.0
output application/json
---
{
  "a" : [0, 1, true, "my string"] ++ [2, [3,4,5], {"a": 6}]
}

Output

{
  "a": [0, 1, true, "my string", 2, [3, 4, 5], { "a": 6}]
}

++(String, String): String

Concatenates the characters of two strings.

Strings are treated as arrays of characters, so the ++ operator concatenates the characters of each String as if they were arrays of single character String.

Parameters

Name Description

source

The source string.

with

The string to concatenate with the source string.

Example

In the example, the Mule is treated as Array<String> ["M", "u", "l", "e"].

Source

%dw 2.0
output application/json
---
{
  "name" : "Mule" ++ "Soft"
}

Output

{
  "name": MuleSoft
}

++(Object, Object): Object

Concatenates two objects and returns one flattened object.

The ++ operator extracts all the key-values pairs from each object, then combines them together into one result object.

Parameters

Name Description

source

The source object.

with

The object to concatenate with the source object.

Example

This example concatenates two objects and transforms them to XML.

Source

%dw 2.0
output application/xml
---
"concat" : {aa: "a", bb: "b"} ++ {cc: "c"}

Output

<?xml version="1.0" encoding="UTF-8"?>
<concat>
  <aa>a</aa>
  <bb>b</bb>
  <cc>c</cc>
</concat>

++(Date, LocalTime): LocalDateTime

Appends a LocalTime with a Date to return a LocalDateTime value.

Date and LocalTime instances are written in standard Java notation, surrounded by pipe (|) symbols. The result is a LocalDateTime object in the standard Java format. Note that the order in which the two objects are concatenated is irrelevant, so logically, Date LocalTime` produces the same result as `LocalTime Date.

Parameters

Name Description

date

A Date.

time

A LocalTime, a time format without a time zone.

Example

This example concatenates a Date and LocalTime object to return a LocalDateTime.

Source

%dw 2.0
output application/json
---
{
  "LocalDateTime" : (|2017-10-01| ++ |23:57:59|)
}

Output

{
   "LocalDateTime": "2017-10-01T23:57:59"
}

++(LocalTime, Date): LocalDateTime

Appends a LocalTime with a Date to return a LocalDateTime.

Note that the order in which the two objects are concatenated is irrelevant, so logically, LocalTime Date` produces the same result as `Date LocalTime.

Example

This example concatenates LocalTime and Date objects to return a LocalDateTime.

Parameters

Name Description

time

A LocalTime, a time format without a time zone.

date

A Date.

Source

%dw 2.0
output application/json
---
{
   "LocalDateTime" : (|23:57:59| ++ |2003-10-01|)
}

Output

{
   "LocalDateTime": "2017-10-01T23:57:59"
}

++(Date, Time): DateTime

Appends a Date to a Time in order to return a DateTime.

Note that the order in which the two objects are concatenated is irrelevant, so logically, Date + Time produces the same result as Time + Date.

Parameters

Name Description

date

A Date.

time

A Time, a time format that can include a time zone (Z or HH:mm).

Example

This example concatenates Date and Time objects to return a DateTime.

Source

%dw 2.0
output application/json
---
{
  "DateTime" : |2017-10-01| ++ |23:57:59-03:00|,
  "DateTime2" : |2017-10-01| ++ |23:57:59Z|
}

Output

{
  "DateTime": "2017-10-01T23:57:59-03:00",
  "DateTime2": "2017-10-01T23:57:59Z"
}

++(Time, Date): DateTime

Appends a Date to a Time object to return a DateTime.

Note that the order in which the two objects are concatenated is irrelevant, so logically, Date + Time produces the same result as a Time + Date.

Parameters

Name Description

time

A Time, a time format that can include a time zone (Z or HH:mm).

date

A Date.

Example

This example concatenates Time and Date objects to return DateTime objects. Note that the first LocalTime object is coerced to a `Time.

Source

%dw 2.0
output application/json
---
{
  "DateTime1" : (|23:57:59| as Time) ++ |2017-10-01|,
  "DateTime2" : |23:57:59Z| ++ |2017-10-01|,
  "DateTime3" : |23:57:59+02:00| ++ |2017-10-01|
}

Output

{
  "DateTime1": "2017-10-01T23:57:59Z",
  "DateTime2": "2017-10-01T23:57:59Z",
  "DateTime3": "2017-10-01T23:57:59+02:00"
}

++(Date, TimeZone): DateTime

Appends a TimeZone to a Date type value and returns a DateTime result.

Parameters

Name Description

date

A Date.

timezone

A TimeZone (Z or HH:mm).

Example

This example concatenates Date and TimeZone (-03:00) to return a DateTime. Note the local time in the DateTime is 00:00:00 (midnight).

Source

%dw 2.0
output application/json
---
{ "DateTime" : (|2017-10-01| ++ |-03:00|) }

Output

{
  "DateTime": "2017-10-01T00:00:00-03:00"
}

++(TimeZone, Date): DateTime

Appends a Date to a TimeZone in order to return a DateTime.

Parameters

Name Description

date

A Date.

timezone

A TimeZone (Z or HH:mm).

Example

This example concatenates TimeZone (-03:00) and Date to return a DateTime. Note the local time in the DateTime is 00:00:00 (midnight).

Source

%dw 2.0
output application/json
---
{ "DateTime" : |-03:00| ++ |2017-10-01| }

Output

{
  "DateTime": "2017-10-01T00:00:00-03:00"
}

++(LocalDateTime, TimeZone): DateTime

Appends a TimeZone to a LocalDateTime in order to return a DateTime.

Parameters

Name Description

dateTime

A LocalDateTime, a date and time without a time zone.

timezone

A TimeZone (Z or HH:mm).

Example

This example concatenates LocalDateTime and TimeZone (-03:00) to return a DateTime.

Source

%dw 2.0
output application/json
---
{ "DateTime" : (|2003-10-01T23:57:59| ++ |-03:00|) }

Output

{
  "DateTime": "2003-10-01T23:57:59-03:00"
}

++(TimeZone, LocalDateTime): DateTime

Appends a LocalDateTime to a TimeZone in order to return a DateTime.

Parameters

Name Description

dateTime

A LocalDateTime, a date and time without a time zone.

timezone

A TimeZone (Z or HH:mm).

Example

This example concatenates TimeZone (-03:00) and LocalDateTime to return a DateTime.

Source

%dw 2.0
output application/json
---
{ "TimeZone" : (|-03:00| ++ |2003-10-01T23:57:59|) }

Output

{
  "TimeZone": "2003-10-01T23:57:59-03:00"
}

++(LocalTime, TimeZone): Time

Appends a TimeZone to a LocalTime in order to return a Time.

Parameters

Name Description

time

A LocalTime, time format without a time zone.

timezone

A TimeZone (Z or HH:mm).

Example

This example concatenates LocalTime and TimeZone (-03:00) to return a Time. Note that the output returns`:00` for the unspecified seconds.

Source

%dw 2.0
output application/json
---
{ "Time" : (|23:57| ++ |-03:00|) }

Output

{
  "Time": "23:57:00-03:00"
}

++(TimeZone, LocalTime): Time

Appends a LocalTime to a TimeZone in order to return a Time.

Parameters

Name Description

time

A LocalTime, a time format without a time zone.

timezone

A TimeZone (Z or HH:mm).

Example

This example concatenates TimeZone (-03:00) and LocalTime to return a Time. Note that the output returns`:00` for the unspecified seconds.

Source

%dw 2.0
output application/json
---
{ "Time" : (|-03:00| ++ |23:57|) }

Output

{
  "Time": "23:57:00-03:00"
}