cancel
Showing results for 
Search instead for 
Did you mean: 

Json splitter for multiple array objects

neelamanikandan
New Contributor II

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"
        }
    ]
}

6 REPLIES 6

RogerSramkoski
Employee
Employee

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?

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

ssapa
Employee
Employee

@neelamanikandan May I know what is you expected output?

Vehicle_IdInceptionDt@_Id$ServiceCompanyAddressLine1ServiceCompanyPhoneServiceCompanyPostalCode
_Id408/03/2023_Id5ServiceCompany45ServiceCompanyAddressLine150ServiceCompanyPhone26ServiceCompanyPostalCode2
_Id408/03/2023_Id5ServiceCompany45ServiceCompanyAddressLine163ServiceCompanyPhone9ServiceCompanyPostalCode15
_Id408/03/2023_Id6ServiceCompany47ServiceCompanyAddressLine150ServiceCompanyPhone26ServiceCompanyPostalCode2
_Id408/03/2023_Id6ServiceCompany47ServiceCompanyAddressLine163ServiceCompanyPhone9ServiceCompanyPostalCode15