I want to do the below dataweave transformation. "SourceValue" should go as "Source" and "SrcVal" in the output payload. Could you please suggest how to do it.
Input:
{ "payload":[
{
"key":"stage",
"value":"Completed"
},
{
"key":"url",
"value":"abc.com"
},
{
"key":"SourceValue",
"value":"abc"
}
]
}
Use the following :
%dw 1.0
%input payload application/json
%output application/json
%var a=2
---
{
part1: payload.payload map ((payload01 , indexOfPayload01) -> {
"key" : "Source" when payload01.key == "SourceValue" otherwise payload01.key,
"value" : payload01.value
}),
part2: payload.payload filter ($.key == "url" or $.key == "SourceValue") map ((payload01 , indexOfPayload01) ->
{
"key" : "SrcVal" when payload01.key == "SourceValue" otherwise payload01.key,
"value" : payload01.value
}
)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.