Layer7 API Management

  • 1.  How to escape Json response

    Posted Nov 19, 2015 03:59 PM

    How do i escape following characters to have a valid json sent in the api response. I have some backend systems returning these characters in their response which i don't want to forward it to the gateway users.

     

    Edit: response from backed is a soap response and i will have to escape only the values in the xml during xslt transformation

     

    string.gif

     

    Regards,

    Ganesh Reddy



  • 2.  Re: How to escape Json response

    Posted Nov 20, 2015 03:47 AM

    Hi Ganesh,

    to escape special characters, you just need to use the backslash (or reverse solidus). For example, if you wanted to send the literal value of something like \/$" then it would become \\\/\$\", as you can see I have put the backslash in front of all the special characters, including itself.

    in order to do this you would need to parse the message through a regular expression assertion that captures and substitutes those particular characters with the same but with an extra backslash in front.

     

    I hope this helps

     

    Maurizio