1

I am trying to add dynamic Post response on one rest API URL(http:IP:9000/page) with data as a JSON request in file format, So to add that file in post body I use the command:

{__$FileToString(C:\Users\user\Desktop\Test\${__eval(${Json_request.txt})},,)}

and the JSON file data is:

{

"User ID": 204120,

"name": "New User",


"Description": [{"john",204110,"robotics"},

                 {"smith",204111,"AI"},

                 {"Jack",204112,"Machinelearning"}]
"Status": "Post request Successfully"

}

But after running this script there is an error in the response body in view results tree:

{"timestamp":1574329356300,"status":400,"error":"Bad 
Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException",
"message":"JSON parse error: Unexpected character ('_' (code 95)): was expecting double-quote to start field name; nested exception is 
com.fasterxml.jackson.core.JsonParseException: Unexpected character 
('_' (code 95)): was expecting double-quote to start field name\n at 
[Source: java.io.PushbackInputStream@73210d3e; line: 1, column: 3]","path":"/page"}
2
  1. Your data is not a valid JSON, you can check it yourself using i.e. online JSON formatter and validator

    enter image description here

  2. You syntax of combination of __eval() and __FileToString() functions is incorrect, you should wrap the __FileToString() function into the __eval() and you're doing the opposite thing:

    ${__eval(${__FileToString(${Json_request.txt},,)})}
    

    More information: Here’s What to Do to Combine Multiple JMeter Variables

| improve this answer | |
2

Your JSON is not valid:

1 {
2   "User ID": 204120,
3   "name": "New User",
4   "Description": [{
5       "name": "john",
6       "id": 204110,
7       "type": "robotics"
8   }],
9   "Status": "Post request Successfully"
10 }

You need to add a name to the value on lines 5,6,7

Or you need to remove the {} brackets to make it valid

"Description": [ "john", 204110, "robotics" ]

Also you missed a comma on line 8, at the end of the Description block.

Maybe you should study the JSON format: http://www.json.org/ and use a JSON validator first https://jsonlint.com/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.