I have this input payload
{
"order": [{
"name": "mule",
"country": "USA",
"id": "mule12"
},
{
"name": "soft",
"country": "brazil",
"id": "mule12"
},
{
"name": "tim",
"country": "java",
"id": "tim12"
},
{
"name": "los",
"country": "angelas",
"id": "tim12"
}
]
}
required output is
{
"mule12": [
{
"name": "mule",
"country": "USA"
},
{
"name": "soft",
"country": "brazil"
}
],
"tim12": [
{
"name": "tim",
"country": "java"
},
{
"name": "los",
"country": "angelas"
}
]
}
I have tried It using group By but I am getting the Id field and I want to remove it. Thanks In advance
Anurag Sharma (Nagarro) Forum Ambassador
Hello @Zakir Kh ,
you can try this, I have used groupBy and then removed the "id" field
%dw 2.0
output application/json
var test = payload.order groupBy ((item, index) -> item.id)
---
test mapObject ((value, key, index) -> (key): value map $-"id" )
item." style="display: block;" />