How to escape double quotes in a JSON?

Smith Johnson
Tera Guru

Hi community,

I have the following field where the user can insert any character. For example:

find_real_file.png

Then, behind the scenes once the form is submitted, a script include makes a REST API call.
However, the double quotes that the user inserted make the integration fail.

The request body looks like this:

find_real_file.png

Any ideas on how to solve this??

 

Thank you in advance,

Smith.

1 ACCEPTED SOLUTION

use to \\ to escape

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

how are you setting the request body?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

if you are using variable substitution in rest message then you can use this method

setStringParameterNoEscape();

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi,

 

First, I have something like this (where "vs_description" is the name of the field).

var description=String(variables.vs_description);

 

Then, as you said I am using the NoEscape method to substitute the "description" variable in the rest message:

wsObject.setStringParameterNoEscape("description", description);

@Ankur Bawiskar Hello, any updates / thoughts on this? It might be really helpful for me.