Skip to main content

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

4 Antworten
  1. Anurag Sharma (Nagarro) Forum Ambassador
    4. Mai 2022, 04:27

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

    Hello @Zakir Kh​ , you can try this, I have used groupBy and then removed the item." style="display: block;" />

0/9000