Naga Raj
Naga Raj

Reputation: 19

Mule | Data weave | Merge / Concat two objects in json

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

Answers (1)

aled
aled

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

Related Questions