Mule 使用dataweave创建json数组
如果我有这样的xmlMule 使用dataweave创建json数组,mule,dataweave,Mule,Dataweave,如果我有这样的xml <Root> <Authority>Water</Authority> <Sanctions> <Sanction> <SanctionCode>11</SanctionCode> <SanctionDesc>First Sanction</SanctionDesc> </Sanction> <
<Root>
<Authority>Water</Authority>
<Sanctions>
<Sanction>
<SanctionCode>11</SanctionCode>
<SanctionDesc>First Sanction</SanctionDesc>
</Sanction>
<Sanction>
<SanctionCode>11</SanctionCode>
<SanctionDesc>Second Sanction</SanctionDesc>
</Sanction>
</Sanctions>
</Root>
我希望我的输出像这样
{
"records": [{
"Authority": "Water",
"sanctions": ["First Sanction", "Second Sanction"]
}]
}
试试这个
%dw 1.0
%output application/json
---
records: {
Authority: payload.Root.Authority,
sanctions: payload.Root.Sanctions..SanctionDesc
}
或
希望这能有所帮助。在从输入有效负载中拾取和选择元素时,理解map操作符是关键。Map操作符遍历左侧的所有数组元素,我们可以从右侧的数组元素中选取值,例如Mulesoft portal %dw 1.0 %输出应用程序/json 用户:[“约翰”、“彼得”、“马特”]地图((名字、位置)->位置++“:“++上名字) 输出: { “用户”:[ “0:JOHN”, “1:彼得”, “2:马特” ] } 请参阅下面的链接:
谢谢。我能问你在制裁面前的*是什么意思吗?只是指每个人吗?我一直试图在某个地方找到一个定义,但没有找到一个好的定义。
*
用于dataweave的一个选择器中。有关更多详细信息,请参阅。
%dw 1.0
%output application/json
---
records: {
Authority: payload.Root.Authority,
sanctions: payload.Root.Sanctions..SanctionDesc
}
%dw 1.0
%output application/json
---
records: {
Authority: payload.Root.Authority,
sanctions: payload.Root.Sanctions.*Sanction map $.SanctionDesc
}