'Dataweave transformation array of elements into string
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")
Solution 1:[1]
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 " "
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | aled |
