What is the use of flatten in DataWeave?
Converts a set of subarrays (such as [ [1,2,3], [4,5], [null] ]) into a single, flattened array (such as [ 1, 2, 3, 4, 5, null ])
Note: The null arrays will be excluded in the output
Also Read: 12 Useful list of Predefined variables in Dataweave MuleSoft

Combine two arrays into a single JSON array using DataWeave flatten
Input:
[
[
{
"key":"abc"
},
{
"key":"def"
}
],
[
{
"key":"123"
},
{
"key":"456"
}
]
]
Output:
[
{
"key": "abc"
},
{
"key": "def"
},
{
"key": "123"
},
{
"key": "456"
}
]
DataWeave Code:
%dw 2.0
output application/json
---
flatten(payload)
Stay tuned to this blog for more DataWeave tutorials and MuleSoft articles. Please share with your MuleSoft friends & colleagues. To discover the free resources available on the internet visit Freeble
0 Comments