Mule 4:Dataweave:如何进行以下转换?

Mule 4 : Dataweave : how to do the below transformation?

请帮忙完成以下转换

输入:

[{"id":1,"sub":["tamil"]},{"id":2,"sub":["english","maths"]},{"id":3,"sub":["phy","che"]}]

输出:

[
{"id":1,"sub":"tamil"},
{"id":2,"sub":"english"},
{"id":2,"sub":"maths"},
{"id":3,"sub":"phy"},
{"id":3,"sub":"che"}
]```

您可以使用以下 DataWeave 表达式:

%dw 2.0
output application/json
---
flatten(payload map ((item1, index) -> 
    flatten(item1.sub map ((item2, index) -> {
        "id": item1.id,
        "sub": item2
    })
)))