谁能根据输入数据(数组对象的项)为下面的输出结构提供DataWeave逻辑?
输入数据
{
"Items": [{
"name": "Document",
"value": ["Representative", "Manager"]
}, {
"name": "Product",
"value": ["Sales", "Price"]
}]
}
输出数据:
^(+Document:"Representative" +Document:"Manager") ^(+Product:"Sales" +Product:"Price")
解决这个问题的最佳方法是使用map
函数和joinBy
函数的组合
%dw 2.0
output text/plain
---
payload.Items
map ((item, index) -> "^(" ++
(item.value
map ((value, index) -> '+$(item.name):"$(value)"')
joinBy " ")
++ ")"
)
joinBy " "