
Input json:
[
{
"SR#": "1",
"PropertyName": "shipToaddres",
"YES": "success",
"NO": "fail",
"NA": "fail"
},
{
"SR#": "2",
"PropertyName": "billToadress",
"YES": "fail",
"NO": "fail",
"NA": "success"
}
]
required output:
{
"shipToaddres": "success",
"billToadress": "success"
}
dwl:
%dw 2.0
output application/json
var a = {
"shipToaddres": "YES",
"billToadress": "NA"
}
fun mapper(k,b) = payload map ((item, index) -> if(item.PropertyName ~= k ) item.b else "") joinBy ""
---
a mapObject ((value, key, index) ->(key): mapper((key),value) )
II dont understand why item.b resolves to null
In case of more than two objects in payload, you can do it in below way as well if it is relevant to your use case.
%dw 2.0
output application/json
var a = {
"shipToaddres": "YES",
"billToadress": "NA"
}
var payloadMapper = {(payload map(
($.PropertyName) : $
))}
---
payloadMapper mapObject ((value, key, index) ->{
(key): value[a[key]]
} )