09-21-2020 01:56 AM
Hello All,
I have a requirement where I have to merge two same keys within a JSON array to form a JSON array of themselves. The below provided examples will clear the requirement:
Input JSON:
[{
“header”: {
“batch_id”: “PVTS_20200919_866184”,
“company_code”: 200,
“region”: “LSA”,
“line”: [{
“projectnumber”: “1000165”,
“io_number”: “200-3754”,
“amount”: “4207.20”,
“id”: 1
}, {
“projectnumber”: “1000165”,
“io_number”: “200-345233”,
“amount”: “1682.88”,
“id”: 2
}]
}
}, {
“header”: {
“batch_id”: “PVTS_20200919_866184”,
“company_code”: 334,
“region”: “S4F”,
“line”: [{
“projectnumber”: “1000173”,
“io_number”: “334-674294”,
“amount”: “4522.74”,
“id”: 1
}]
}
}]
Required out put is to form a JSON with header key being the root array and everything else comes under it.
Required Output Example:
{
“header”: [{
“batch_id”: “PVTS_20200919_866184”,
“company_code”: 200,
“region”: “LSA”,
“line”: [{
“projectnumber”: “1000165”,
“io_number”: “200-3754”,
“amount”: “4207.20”,
“id”: 1
}, {
“projectnumber”: “1000165”,
“io_number”: “200-345233”,
“amount”: “1682.88”,
“id”: 2
}]
},
{
“batch_id”: “PVTS_20200919_866184”,
“company_code”: 334,
“region”: “S4F”,
“line”: [{
“projectnumber”: “1000173”,
“io_number”: “334-674294”,
“amount”: “4522.74”,
“id”: 1
}]
}
]
}
I’ve tried few things, but it doesn’t seem to help. Can someone please provide any insights on how to achieve this?
Solved! Go to Solution.
09-21-2020 04:31 AM
Hi Tanmay,
You can use Gate snap to setup the streaming documents into array, then you can manipulate the array from there.
09-21-2020 04:31 AM
Hi Tanmay,
You can use Gate snap to setup the streaming documents into array, then you can manipulate the array from there.
09-21-2020 09:04 AM
Thank you for this @alchemiz . This did the job.
I tried another way too with the help of a mapper and group by N snap.