I am trying to transform an xml based on groupBy in dataweave, however I also need to remove few json attributes from output.
Input json:
[ {
"m": {
"a": "a",
"b": "b"
},
"tag1": "A",
"tag2": "v1",
"tag3": "v1" }, {
"m": {
"a": "a",
"b": "b"
},
"tag1": "A",
"tag2": "v2",
"tag3": "v2" }, {
"m": {
"a": "a",
"b": "b"
},
"tag1": "C",
"tag2": "v3",
"tag3": "v3" } ]
Output json
**{
"A": [
{
"tag2": "v1",
"tag3": "v1"
},
{
"tag2": "v2",
"tag3": "v2"
}
],
"C": {
"tag2": "v3",
"tag3": "v3"
}
}**
I have tried following transformation (Mule 3.9) however the could not remove the extra attributes in json.
payload groupBy (item) -> item.tag1
Appreciate any suggestion on this and possibly explain how this can be achieved.
The way to iterate over an object is using mapObject and then you can filter the objects to remove the elements that are not wanted
This will output