Need your help in transform a message like below using DataWeave 2.0.
If I have the following JSON payload of users, with a group and subgroup.
[
{
"GROUP": "GROUP_A",
"SUBGROUPS": [{
"NAME": "SUBGROUP A1",
"USERS": "USER 1"
}]
}, {
"GROUP": "GROUP_B",
"SUBGROUPS": [{
"NAME": "SUBGROUP B1",
"USERS": "user 2"
}, {
"NAME": "SUBGROUP B2",
"USERS": ["USER 3", "USER 4", "USER 5"]
}]
}
]
What would a DataWeave transformation look like to tranform the payload to something structured like the following:
[{
"GROUP": "GROUP_A",
"SUBGROUP": "SUBGROUP A1",
"USER": "USER 1"
},
{
"GROUP": "GROUP_B",
"SUBGROUP": "SUBGROUP B1",
"USER": "USER 2"
}, {
"GROUP": "GROUP_B",
"SUBGROUP": "SUBGROUP B2",
"USER": "USER 3"
}, {
"GROUP": "GROUP_B",
"SUBGROUP": "SUBGROUP B2",
"USER": "USER 4"
}, {
"GROUP": "GROUP_B",
"SUBGROUP": "SUBGROUP B2",
"USER": "USER 5"
}]
I was trying with flatten but that does not work.
Thanks for any help!