I'm currently testing a web application which outputs json. I want to make sure that the JSON is valid. I do not want to validate its content. How can I implement a assertion in jmeter to make sure that the json response is valid?
Thanks!
I'm currently testing a web application which outputs json. I want to make sure that the JSON is valid. I do not want to validate its content. How can I implement a assertion in jmeter to make sure that the json response is valid?
Thanks!
Use beanshell assertion, jsr223 assertion or bsf assertion if you want to use groovy:
and parse the response using some json parser:
Jmeter will provide to your script the previous sampler response as a script variable.
Note that this can impact performance of your test plan as it's rather costly.
Regards
I normally use javascript BSF Assertion. Since JSON are javascript objects you can try to eval the response in a try-catch block and in case it fails you can explicitly fail the previous SampleResult.
try {
eval('var response = ' + prev.getResponseDataAsString());
} catch(e) {
prev.setSuccessful(false);
prev.setResponseMessage("Invalid response. Expected a valid JSON.");
}