i'm facing an issue while trying to change data from payload and converting it to another api which requires different type of input with same values
input payload
{"metadata":
{"attributes":
[
{
"name":"FromDate",
"value":"22-09-2021"
},
{
"name":"ToDate",
"value":"22-02-2022"
}
{
"name":"Purchased",
"value":"21-02-2021"
}
]
}
}
expected output payload
{"attributes":
{
"FromDate":"22-09-2021",
"ToDate":"22-02-2022",
"Purchased":"21-02-2021"
}
}
i have tried the below code to transform the data but unable to acheive the result
%dw 2.0
output application/json
---
{
"attributes": payload."metadata"."attributes" map ((item, index) -> {(item."name"):item."value"})
}
any suggestions and answers are welcome
You could as well do something purely using map.
%dw 2.0
output application/json
---
attributes: {(payload.metadata.attributes map {
($.name): ($.value)
})}