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