Double slash in output when using xml-to-json policy

We are using xml to json policy. There is one field in the output which has a single slash in the data.

But the apigee is returning double slash for that field as below:

 

 "networkId": "ABC\\JACK09",

The actual data is

 

 "networkId": "ABC\JACK09",
 
Below is the policy code
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XMLToJSON continueOnError="false" enabled="true" name="XML-to-JSON-Formatoutput">
<DisplayName>XML to JSON-Formatoutput</DisplayName>
<Properties/>
<Format>xml.com</Format>
<OutputVariable>response</OutputVariable>
<Source>response</Source>
</XMLToJSON>

 

0 1 883
1 REPLY 1

That's expected. I suppose you're looking at the Trace UI or something, to detect that the slash has been doubled.

 

The backslash is a special character in JSON. It is used to "escape" the next character in the string. [ link1, link2 ] If you want the backslash to be just backslash, then in a JSON encoding, you need to escape it with another backslash, which results in the string that you observed. The same is true if you were encoding that string value into a program written in  JavaScript, Java, PHP, C#, C, or C++.  Escape those backslashes. 

If you had an app that digested that JSON (in JavaScript, via JSON.parse(), or in Java, via Gson.fromJson() or similar, etc), then the resulting value of doc.networkId will be "ABC\JACK09". Which I think is what you want.