cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Parsing XML Array to JSON array is inconsistent

mohamadelmardin
New Contributor III

When using XML parser snap to parse XML documents we are facing a problem when handling XML array type. This is because XML parser parses XML Array at runtime to either a JSON array if the particular element in the incoming XML message comes as array or as a single JSON object/element if the particular element in the incoming XML message comes as a single element not as an array. This is causing a major problem down the processing pipeline especially when using Mapper or any similar snaps where the parsed JSON data comes either as an array or as element {} and pipeline breaks for error.

The question is how can we force XML parser or combine it with any other technique so that it will parse XML element to JSON always as an array even if it comes as a single XML array element. Attached is an example of a simple pipeline reading an xml file with attached schema xsd. If the XML item element cames as an array then the pipeline will process successfully til the tend but if it comes as a single item then it will definitely fails at Mapper because JSON cannot treat it as an array
ParsingXMLArray_2017_07_24.slp (4.5 KB)
shippingtestingschema.xsd.txt (1.2 KB)
shiporder.xml.txt (673 Bytes)
shiporder_OneItem.xml.txt (527 Bytes)

8 REPLIES 8

del
Contributor III

Specifically for your example pipeline, try adding a new Mapper with the following configuration immediately after your XML Parser:

415b38f9b5c6003da4cffad57ab27056082bec01.png

(note the Pass through selection)

mohamadelmardin
New Contributor III

Thank you @del . This solution resolved my issue.
So let me put it differently now. Aside from my specific example and assuming that I have just to parse from XML to JSON and write it as-is without using any mapping/transformation to a JSON file to an external system but with the array format always enforced even with one element, Is there a way to do it in the XML parser by let us say for example checking the validate against XSD schema? Or do I have to use a mapper always to clean it and enforce the array on it?

The reason I am asking again because the XML I gave was just a simple example but in my real scenario the XML payload I am working in has more than a 100 elements and multiple nested array structure. so that means I have to use a mapper for each expected array in order to check it and use the [].concat[element] on it ?!

Hi,

Am also looking for solution for similar kind of issue with multiple elements having array structure, Did you find any solution in xml parser or added multiple mappers?

TIA,
Shruthi

@nshruthi
No I didnโ€™t. Unfortunately SnapLogic doesnโ€™t have an out-of-box solution in the XML parser to handle XML array transformation gracefully. I have an enhancement request opened with support but I havenโ€™t heard any resolution on it yet and still waitingโ€ฆ