1

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"
    }
]

1 Answer 1

5

You can use the descendant selector and then use the attributes selectors

%dw 2.0
output application/json
---
tracking_no: payload..*Container.@
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.