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-05-2023 01:16 PM
Hi @neelamanikandan ,
Good day, see if this will work place the expression in a mapper
sl.ensureArray($ServiceCompanyArray).map(c=> sl.ensureArray($ServiceCompanyDetailArray).map(d=> {'Vehicle_Id': $Vehicle_Id, 'InceptionDt': $InceptionDt}.merge(c.merge(d)))).reduce((a,b)=> a.concat(b),[])
Thanks,
EmEm
08-07-2023 02:25 AM
This works Thank You!
But this will also be a too much of coding when we have multiple attributes, and multiple arrays. Anyways thanks for this solution, we can take it from here.