cancel
Showing results for 
Search instead for 
Did you mean: 

Transforming into JSON Array

Tanmay_Sarkar
New Contributor III

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?

1 ACCEPTED SOLUTION

alchemiz
Contributor III

Hi Tanmay,

You can use Gate snap to setup the streaming documents into array, then you can manipulate the array from there.

image

View solution in original post

2 REPLIES 2

alchemiz
Contributor III

Hi Tanmay,

You can use Gate snap to setup the streaming documents into array, then you can manipulate the array from there.

image

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.
image