Forum Discussion

Tanmay_Sarkar's avatar
Tanmay_Sarkar
New Contributor III
5 years ago
Solved

Transforming into JSON Array

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?

  • Hi Tanmay,

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

2 Replies

  • Hi Tanmay,

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