Reputation: 23
In dataweave, I want to transform the below complex xml to json output as shown below:
<Message>
<Shipment>
<Containers>
<Container TrackingNo="Abc1" />
</Containers>
</Shipment>
<Shipment>
<Containers>
<Container TrackingNo="Abc2" />
<Container TrackingNo="Abc3" />
</Containers>
</Shipment>
<Shipment>
<Containers>
<Container TrackingNo="Abc4" />
<Container TrackingNo="Abc5" />
<Container TrackingNo="Abc6" />
</Containers>
</Shipment>
</Message>
I want to get the output in below JSON format after transformation in dataweave:
tracking_no:[
{
TrackingNo="Abc1"
},
{
TrackingNo="Abc2"
},
{
TrackingNo="Abc3"
},
{
TrackingNo="Abc4"
},
{
TrackingNo="Abc5"
},
{
TrackingNo="Abc6"
}
]
Upvotes: 1
Views: 314
Reputation: 5059
You can use the descendant selector and then use the attributes selectors
%dw 2.0
output application/json
---
tracking_no: payload..*Container.@
Upvotes: 5