JMeter - JSON parse error: Unexpected character



  • 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"}
    


    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



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2