Contact Us 1-800-596-4880

unzip

DataWeave 2.2 is compatible and bundled with Mule 4.2. This version of Mule reached its End of Life on May 2, 2023, when Extended Support ended.

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.

unzip(Array<Array<T>>): Array<Array<T>>

Performs the opposite of zip. It takes an array of arrays as input.

The function groups the values of the input sub-arrays by matching indices, and it outputs new sub-arrays with the values of those matching indices. No sub-arrays are produced for unmatching indices. For example, if one input sub-array contains four elements (indices 0-3) and another only contains three (indices 0-2), the function will not produce a sub-array for the value at index 3.

Parameters

Name Description

items

The input array of arrays.

Example

This example unzips an array of arrays. It outputs the first index of each sub-array into one array [ 0, 1, 2, 3 ], and the second index of each into another [ "a", "b", "c", "d" ].

Source

%dw 2.0
output application/json
---
unzip([ [0,"a"], [1,"b"], [2,"c"],[ 3,"d"] ])

Output

[ [ 0, 1, 2, 3 ], [ "a", "b", "c", "d" ] ]

Example

This example unzips an array of arrays. Notice that the number of elements in the input arrays is not all the same. The function creates only as many full sub-arrays as it can, in this case, just one.

Source

%dw 2.0
output application/json
---
unzip([ [0,"a"], [1,"a","foo"], [2], [3,"a"] ])

Output

[0,1,2,3]