Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMeter Variables in JSON request

When I pass an variable in JMeter HTTP request, I'm getting an exception

"Unexpected escape character after back slash"

The request body:

 "Draft":{
"id": 123654656,
"draftdata":{\\\"accCat\\\":\\\"207\\\",\\\"accNumber\\\":\\\"656565
\\\",\\\"id\\\":${Var_ID},...}
}

When I send the request, one of the two back-slashes are omitted. I guess the variable ${Var_ID} should be passed in a way that does not conflict with the json body

like image 974
Robert Avatar asked Apr 22 '26 21:04

Robert


2 Answers

  1. I don't think you need these \\\ signs
  2. I believe you need to surround ${Var_ID} with quotation marks

Something like:

{
  "id": 123654656,
  "draftdata": {
    "accCat": "207",
    "accNumber": "656565 ",
    "id": "${Var_ID}"
  }
}

You can use online JSON validation tools like Online JSON Viewer to test your JSON payload. Also check out Testing SOAP/REST Web Services Using JMeter article for some initial information on testing REST APIs using JMeter

like image 80
Dmitri T Avatar answered Apr 25 '26 14:04

Dmitri T


Maybe making changes like:

{
   "Draft": {
       "id": 123654656,
       "draftdata": {
           \"accCat\":\"207\",
           \"accNumber\":\"656565\",
           \"id\":\"${Var_ID}\",...}
}

I don't see any need to have \ signs, just one will escape original " signs.

like image 26
Iske Avatar answered Apr 25 '26 13:04

Iske



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!