08-04-2023 05:54 AM
I have a Json input that contains multiple array objects within it. Json sample given below. I'm trying to flatten this data into table rows, I use two json splitter to achieve this.
First Json splitter with Split path $ServiceCompanyArray and then a mapper to map the split value and then another Json splitter with split path $ServiceCompanyDetailArray and then another mapper to Writer.
Note: this is an xample Json, the actual Json could have multiple array fields, so should we always use N number of json splitters.
{
"Vehicle_Id": "_Id4",
"InceptionDt": "2023-08-03",
"ServiceCompanyArray": [
{
"@_Id": "_Id5",
"$": "ServiceCompany45"
},
{
"@_Id": "_Id6",
"$": "ServiceCompany47"
}
],
"ServiceCompanyDetailArray": [
{
"ServiceCompanyAddressLine1": "ServiceCompanyAddressLine150",
"ServiceCompanyPhone": "ServiceCompanyPhone26",
"ServiceCompanyPostalCode": "ServiceCompanyPostalCode2"
},
{
"ServiceCompanyAddressLine1": "ServiceCompanyAddressLine163",
"ServiceCompanyPhone": "ServiceCompanyPhone9",
"ServiceCompanyPostalCode": "ServiceCompanyPostalCode15"
}
]
}
08-04-2023 06:06 AM
Hi @neelamanikandan, thank you for joining the SnapLogic Community within the last few weeks and for sharing how you split multiple array objects. I just want to double check, did you have a question about how you split the JSON arrays or were you just sharing a solution?
08-04-2023 06:14 AM
Hi @RogerSramkoski It was a question, in the above example I had 2 (Servicecompany and Servicecompanydetail) fields that had values in array, so I have used 2 JSON splitters in the pipeline. But if my input JSON contains multiple(eg. 10) array fields should I always use multiple (10 JSON splitters) in the pipeline? Is there alternate Snap that can flatten all the Array elements at one go, or is there an alternative approach to use the JSON splitter to flatten all arrays
08-04-2023 04:38 PM
@neelamanikandan May I know what is you expected output?
08-04-2023 10:12 PM
Vehicle_Id | InceptionDt | @_Id | $ | ServiceCompanyAddressLine1 | ServiceCompanyPhone | ServiceCompanyPostalCode |
_Id4 | 08/03/2023 | _Id5 | ServiceCompany45 | ServiceCompanyAddressLine150 | ServiceCompanyPhone26 | ServiceCompanyPostalCode2 |
_Id4 | 08/03/2023 | _Id5 | ServiceCompany45 | ServiceCompanyAddressLine163 | ServiceCompanyPhone9 | ServiceCompanyPostalCode15 |
_Id4 | 08/03/2023 | _Id6 | ServiceCompany47 | ServiceCompanyAddressLine150 | ServiceCompanyPhone26 | ServiceCompanyPostalCode2 |
_Id4 | 08/03/2023 | _Id6 | ServiceCompany47 | ServiceCompanyAddressLine163 | ServiceCompanyPhone9 | ServiceCompanyPostalCode15 |