I have an input payload containing array of objects where I need to group-by
id-key and form 2 arrays of objects based on id-key. See below details.
input Payload:
{
"id": {
"header_id": "460",
"id-branch": {
"branch-name": "genaral motors",
"req-name": "genaral motors",
"id-key": "0791",
"id-lines": {
"id-key": "0791",
"productId": "463"
}
},
"id-branch": {
"branch-name": "genaral motors",
"req-name": "genaral motors",
"id-key": "9692",
"id-lines": {
"id-key": "9692",
"productId": "464"
},
"id-lines": {
"id-key": "9692",
"productId": "465"
}
}
}
}
desired Ouput:
[
{
"branch-name": "genaral motors",
"req-name": "genaral motors",
"type": "dhl",
"lines-ids": "swr",
"lines": [
{
"productId": "463"
}
]
},
{
"branch-name": "genaral motors",
"req-name": "genaral motors",
"type": "dhl",
"lines-ids": "swr",
"lines": [
{
"productId": "464"
},
{
"productId": "465"
}
]
}
]
the output has to be generated as array of object which groups productId which are under same id-key.