Extract Variable JSON payload introducing escape character for "/"

Hi,

We have a back end response that contains "/" and we use the Extract Variable policy to extract the node that contains this character inside. The EV policy introduces an escape character to the "/" so the response has data looking like "xxxxx \/ xxx" when we want it to be "xxx / xxx". I would have thought forward slashes are not escaped? How can this be avoided?

Thanks.

.........................................................................

0 10 2,841
10 REPLIES 10

Do you have an example of how your policy is currently configured?

EV.ExtractResponseData data

<ExtractVariables name="EV.ExtractResponseData">
    <DisplayName>EV.ExtractResponseData</DisplayName>
    <JSONPayload>
        <Variable name="data" type="object">
            <JSONPath>data</JSONPath>
        </Variable>
    </JSONPayload>
</ExtractVariables>

The AM policy is :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="AM.SetRetailersResponse">
    <DisplayName>AM.SetRetailersResponse</DisplayName>
    <Properties/>
    <Set>
        <Payload contentType="application/json">
            { "data": {data}, "links": { "self": "{selfLink}" } }
        </Payload>
    </Set>
    <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>

Hi @sarah fernando, can you please provide the request payload sample for debugging perspective?

The request is something like:

{"data":{"test":[
{"id":"1010","name":"1st Ene Pty Ltd"},
{"id":"2034","name":"Click Ene / Am Ene"}]}

And we see the response after EV policy as :

{"data":{"test":[
{"id":"1010","name":"1st Ene Pty Ltd"},
{"id":"2034","name":"Click Ene \/ Am Ene"}]}

ev-demo-rev2-2019-07-26.zip

I am not getting the error now, here is the sample proxy I have attached.

8925-screen-shot-2019-07-26-at-90320-pm.png

The extract variable is adding the \ as you mentioned.

Try a javascript implementation instead to do the same thing (Get the data field from a json response, and assign to data variable) such as follows

	var response = context.getVariable('response.content')
	var responseJson = JSON.parse(response)
	context.setVariable('data', JSON.stringify(responseJson.data))

This is true, and also, the backslash is benign. See my answer.

I see that the problem you described - unnecessary backslash-escape of a forward slash - seems to have gone away?

Just wanted to point out that in JSON, the backslash escape of a forward slash should be benign. Nothing to worrry about. It should be handled by the JSON processor transparently.

ref: https://stackoverflow.com/a/1580664/48082