0
votes

I can not figure out why I get this error:

"Failed to parse request body as JSON resource. Error was: Failed to parse JSON encoded FHIR content: Unrecognized token 'json': was expecting ('true', 'false' or 'null')\n at [Source: UNKNOWN; line: 3, column: 29]"

FHIR is the standard used. I also tested with a valid JSON that worked with Postman, so I don't think the actual JSON is the issue. I'm not sure if I'm correct, but it seems JMeter adds 'json' from somewhere as the error states the token 'json' is unexpected. This is the Request > Request body tab in View Results Tree.

JSON request body

This is just a test JSON, but I got the same response with a JSON body that is working in Postman (and I formatted correctly to be sure). I have the Content-Type header specified. I simply don't understand where the token 'json' would come from as my json itself doesn't contain the token. Does anybody know if JMeter adds something to the request?

2

2 Answers

0
votes

You're sending incorrect payload, it should look like:

{
     "test" : "X"
}

and you are sending

{
     "test" : "X"
}json

 ^^^^ this guy is causing the issue

JMeter doesn't add anything to request, you need to double check your configuration, i.e. JMeter jmx scripts are "normal" XML files so you can use your favorite text editor to look up this json

If you're able to send a valid request using Postman you should be able to record it using JMeter's HTTP(S) Test Script Recorder, just configure Postman to use JMeter as the proxy and run your request/collection - JMeter will capture the requests and generate relevant HTTP Request samplers which can be replayed successfully.

More information: How to Convert Your Postman API Tests to JMeter for Scaling

0
votes

It happened to be that if you add a default parameter in an HTTP Request Defaults (in my case _format=json), it would add it to the body of the POST.

I fixed this by adding a BeanShell PreProcessor with the code:

if(sampler.getMethod().equalsIgnoreCase("get")){ sampler.addArgument("_format", "json"); }