我需要为输入中的每个对象在 json 数组中输入两个对象。
为此,我编写了以下代码:
%dw 2.0
output application/csv
var categoryList = ["Business","Authorization"]
---
payload map((payload01,indexOfPayload01)->
categoryList map((payload02,indexOfPayload02)->
{
"Name": payload01.Name,
"Category":payload02,
"Code":"Customer",
"Percentage":null,
"End Tag": "End"
})
)
我的输出是:
[
[
{
"Name": "Desc 1",
"Category": "Business",
"Code": "Customer",
"Percentage": null,
"End Tag": "END"
},
{
"Name": "Desc 1",
"Category": "Authorization",
"Code": "Customer",
"Percentage": null,
"End Tag": "END"
}
],
[
{
"Name": "Desc 2",
"Category": "Business",
"Code": "Customer",
"Percentage": null,
"End Tag": "END"
},
{
"Name": "Desc 2",
"Category": "Authorization",
"Code": "Customer",
"Percentage": null,
"End Tag": "END"
}
]
]
但我希望这些值作为单个 json 数组。在这里,数据被分成两个对象。我的预期输出:
[
{
"Name": "Desc 1",
"Category": "Business",
"Code": "Customer",
"Percentage": null,
"End Tag": "END"
},
{
"Name": "Desc 1",
"Category": "Authorization",
"Code": "Customer",
"Percentage": null,
"End Tag": "END"
},
{
"Name": "Desc 2",
"Category": "Business",
"Code": "Customer",
"Percentage": null,
"End Tag": "END"
},
{
"Name": "Desc 2",
"Category": "Authorization",
"Code": "Customer",
"Percentage": null,
"End Tag": "END"
}
]
我怎样才能完成这项工作?不用说,我是 Mule 的新手。
谢谢,阿努普