Convert empty fields with XML to JSON Policy

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 ?

1 1 605
1 REPLY 1

We can use the RecognizeNull and NullValue elements under <Options> 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>