Hi All,
I tried this in Dataweave 1.0 and it works perfectly fine, however the same gives me error in Dataweave 2.0. Can some one please help me achieve the same output in 2.0
Input :
%dw 1.0
%output application/json
---
{
([1,2] map ({
test: 1
}) ++
({type : "filter"}))
}
Output:
{
"test": 1,
"test": 1,
"type": "filter"
}
Thanks :)
Yes, as written, it was trying to concatenate an array with an object. Concatenate only works with like data types, so you have two options:
Changing the () to [] on the last object produces an array of three objects, and the constructor/evaluation notation {( )} converts that to an object with three key:value pairs.
Array concatenation:
{ ( [1,2] map ( {test: 1} ) ++ [ {"type" : "filter"} ] ) }
Moving the closing )} immediately after the first object produces an object with two key:value pairs, which is then concatenated with the second object.
Object concatenation:
{ ( [1,2] map ( {test:1} ) ) } ++ ( {"type": "filter"} )
Incidentally, you can remove the () from around all objects in both examples. You only need the {( and )}.