Reputation: 19
I'm working on one scenario where I'm expecting the below output by giving the input.
Input:
[{
"Name": "",
"Age": 30,
"Color": "",
"Height": ""
},
{
"Name": "",
"Age": "",
"Color": "",
"Height": 5.6
}
]
Output:
{Name: "",
Age: 30,
Color: "",
Height: 5.6
}
Upvotes: 0
Views: 503
Reputation: 25699
This solves your case, but it may not work with more complex structures:
%dw 2.0
output application/json
---
payload reduce ((item, acc={}) -> item mapObject (($$): $ ++ (acc[$$] default "")))
This script assumes all elements have the same fields.
Upvotes: 1