We get XML response from our backend server which has some fields empty.We convert the XML to JSON format using XMLToJSON policy.However, during conversion the empty XML fields are converted as braces {}, so the JSON output will come up as follows:
{"Response":{"ErrorDescription":{},"Id":"ABCD","ErrorCode":{},"RecordId":"123456"}}
Instead of curly braces, we would like to have double quotes ββ for empty field as shown below:
{"Response":{"ErrorDescription":"","Id":"ABCD","ErrorCode":"","RecordId":"123456"}}
How can we achieve this ?
2 Likes
We can use the RecognizeNull and NullValue elements under element in XMLToJSON policy to convert empty fields to ββ
Hereβs a sample code that converts empty fields in XML to ββ in JSON output:
<XMLToJSON async="false" continueOnError="false" enabled="true" name="XML-to-JSON">
<DisplayName>XML to JSON</DisplayName>
<Properties/>
<Options>
<RecognizeNull>true</RecognizeNull>
<NullValue>""</NullValue>
</Options>
<OutputVariable>response</OutputVariable>
<Source>response</Source>
</XMLToJSON>
2 Likes
Use like this to avoid escaped quotes:
<NullValue></NullValue>
1 Like