JSON splitter does not split objects properly

I am having an isssue splitting the JSON for an object. I am initially reading an xml and then using XML parser to convert that to JSON document output.

I will try to explain the issue with example. Please note that the input is an xml file. It can have one or more than more DetailRecords as per the different xmls below.
Splitter logic is Json Path field set to - $Root.DetailRecord[*]

XML 1

< HEADER> DEFAULT AUD Tanya F David M

XML 2

< HEADER> DEFAULT AUD Tanya F

• When there are multiple records (Refer XML 1) : Splitter split both the records (DetailRecord) as expected and provide a flat structure with input schema Name and Gender.
• When there is 1 record (Refer XML 2) : Splitter behaves differently. It split the values rather than records and provide values Tanya, F under column splitvalue. So, the logic to transform the data breaks.

My aim is that, whether it is one sub record or more, it should detect that its an object and split it however here if its more then one then it converts it to object and if its one then it leaves that as string and thus I cannot dynamically change whether to use splitter or not and the pipeline fails it I use splitter and it has one record only.

Hi, I was not able to find the xml attachments you list but I think I had the same issue where the were sub-fields under my ‘address’ had multiple sub-records but only if there was data in each. Example being one might only have address1 while the next would have that and address2. I had to break this out after the JSON Splitter in the Mapping snap. Then in each field I had to use the hasOwnProperty function and some ternary logic:

.hasOwnProperty('address.address1') ? .address.address1 : null
.hasOwnProperty('address.address2') ? .address.address2 : null
.hasOwnProperty('address.city') ? .address.city : null
etc…
I also had to create the data table with all the possible fields to match for the mapping.
Here is the URL to this function
https://docs-snaplogic.atlassian.net/wiki/spaces/SD/pages/1439367/Object+Functions+and+Properties#ObjectFunctionsandProperties-hasOwnProperty

Below is a screen shot of my mapping: Hope my upload worked. First time contributing.

1 Like