0

When trying to pass the user defined value to the body content, I am getting error "message": "Bad JSON escape sequence: \S. ---- \r\nUnexpected character encountered while parsing value". When passing complete raw payload through body data, I am not getting this error.

With User defined Variable, "customerBillingAddress":"26 Chestnut St\Suite 2B\Andover, MA 01810",

convert as " "customerBillingAddress":"26 Chestnut St\Suite 2B\Andover, MA 01810","

"\" is throwing error.

When testing with raw data, I am getting as it is in the payload.

     "customerBillingAddress":"26 Chestnut St\\Suite 2B\\Andover, MA 01810",

Please advise

2 Answers2

0

You need to escape \ with \\ and double quote " with \" as per JSON format guideline. Here I think you only need to escape \ in your JSON payload like below .

"customerBillingAddress":"26 Chestnut St\\Suite 2B\\Andover, MA 01810"

Niladri
  • 5,832
  • 2
  • 23
  • 41
0

You need to escape the following characters in JSON:

\b  Backspace (ascii code 08)
\f  Form feed (ascii code 0C)
\n  New line
\r  Carriage return
\t  Tab
\"  Double quote
\\  Backslash character

In order to do this automatically you can use __groovy() function available since JMeter 3.1 like:

${__groovy(org.apache.commons.lang3.StringEscapeUtils.escapeJson(vars.get('json')),)}

Demo:

Groovy Escape JSON JMeter

Dmitri T
  • 159,985
  • 5
  • 83
  • 133