Reputation: 27
Can anyone kindly provide the DataWeave logic for the below output structure based on the input data(Items of the array object).
Input Data
{
"Items": [{
"name": "Document",
"value": ["Representative", "Manager"]
}, {
"name": "Product",
"value": ["Sales", "Price"]
}]
}
Output data:
^(+Document:"Representative" +Document:"Manager") ^(+Product:"Sales" +Product:"Price")
Upvotes: 0
Views: 142
Reputation: 5059
The best way to solve this is by using a combination of map
function and joinBy
%dw 2.0
output text/plain
---
payload.Items
map ((item, index) -> "^(" ++
(item.value
map ((value, index) -> '+$(item.name):"$(value)"')
joinBy " ")
++ ")"
)
joinBy " "
Upvotes: 2