Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Why does extract variables remove backslash characters from a properly escaped JSON property value?

I'm using Extract Variables (EV) to get a "systemMessage" from a backend error response that may contain properly escaped quote chars. EV populates the variable but drops the backslashes.

Then, when I use a subsequent Assign Message (AM) policy to set that value in my standard error response message, the quote chars are not escaped and message is not valid JSON.

Here's my backend response:

{
      "code": "INVALID",
      "user_message": "Invalid value for \"logonId\" check your input."
}

Here's the EV policy:

<ExtractVariables name="EV-BackendErrorResponse">
    <DisplayName>EV-BackendErrorResponse</DisplayName>
    <JSONPayload>
        <Variable name="standard.systemMessage">
            <JSONPath>$.user_message</JSONPath>
        </Variable>
    </JSONPayload>
</ExtractVariables>

Here's the AM policy in DefaultFaultRule:

<AssignMessage name="AM-SetStandardFaultResponse">
    <DisplayName>AM-SetStandardFaultResponse</DisplayName>
    <Set>
        <Payload contentType="application/json">
           {
              "code": "{standard.errorCode}",
              "userMessage": "{standard.userMessage}",
              "systemMessage": "{standard.systemMessage}",
              "info": "http://company.com/docs/errors#{standard.errorCode}"
           }
        </Payload>
        <StatusCode>{standard.errorStatusCode}</StatusCode>
        <ReasonPhrase>{standard.errorReasonPhrase}</ReasonPhrase>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>

Here's the invalid result:

{
      "code": "proxyname.409.001",
      "userMessage": "Invalid credentials",
      "systemMessage": "Invalid value for "logonId" check your input.",
      "info": "http://developer.company.com/docs/errors#proxyname.409.001"
}

Why can't EV just leave well enough alone?

Probably have to use JS callout to process the response and ensure properly escaped values.

1 6 1,703
6 REPLIES 6