Hi Everyone,
I have a scenario where I need to trim the XML from backend and convert into JSON . my payload is like this.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header/> <soap:Body> <Data> . . </Data> </soap:Body> </soapenv:Envelope>
My Config :
<Properties/> <Options> <RecognizeNumber>true</RecognizeNumber> <RecognizeBoolean>true</RecognizeBoolean> <RecognizeNull>false</RecognizeNull> <TextNodeName>content</TextNodeName> <StripLevels>2</StripLevels> </Options>
I just need
{"Data" : "......"...}
Note: I tried different StripLevels like 4,6,8. No luck.
Solved! Go to Solution.
You have 2 options:
You have 2 options:
yes
The StripLevels option strips levels ONLY if there is a single child at each level. The documentation explains this.
If you try XMLToJSON with this configuration,
<XMLToJSON name='XMLToJSON-2'> <Source>testMessage</Source> <OutputVariable>output_json</OutputVariable> <Options> <StripLevels>2</StripLevels> </Options> </XMLToJSON>
with your source XML, then you will see a resulting json, something like this:
{"Header":"","Body":{"Data":"..."}}
Both Header and Body appear. This is because the Header and Body elements are siblings, and as a result, the XMLToJSON won't strip beyond the first level. When there are multiple siblings, there is no way for the logic behind the "StripLevels" option to know which sibling you want to preserve!
The options Debora outlined are the way you can address your requirement.
Yeah, I used the 2 option. However, would like to understand why StripLevels do not work in this scenario. @Dino-at-Google explained me below. Thanks !!
When you say "no luck", what do you mean? What results DO you get?
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |