1

在 dataweave 中,我想将下面的复杂 xml 转换为 json 输出,如下所示:

<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>

在dataweave中转换后,我想获得以下JSON格式的输出:

tracking_no:[
    {
        TrackingNo="Abc1"
    },
    {
        TrackingNo="Abc2"
    },
    {
        TrackingNo="Abc3"
    },
    {
        TrackingNo="Abc4"
    },
    {
        TrackingNo="Abc5"
    },
    {
        TrackingNo="Abc6"
    }
]
4

1 回答 1

5

您可以使用后代选择器,然后使用属性选择器

%dw 2.0
output application/json
---
tracking_no: payload..*Container.@
于 2019-05-17T14:08:42.190 回答