Jmeter statement to check json schema

I am currently testing a web application that outputs json. I want to make sure that JSON is valid. I do not want to check its contents. How can I implement a statement in jmeter to make sure the json response is valid?

Thanks!

+4
source share
2 answers

Use the beanshell statement, the jsr223 statement, or the bsf statement if you want to use groovy:

and parse the answer with some json parser:

Jmeter will provide your script with the previous sampler response as a script variable.

Please note that this may affect the performance of your test plan, as it is quite expensive.

Hello

+3
source

I usually use javascript BSF Assertion . Since JSONs are javascript objects, you can try to evaluate the response in a try-catch block, and if it fails, you can explicitly ignore the previous SampleResult.

try {    eval('var response = ' + prev.getResponseDataAsString()); } catch(e) {       prev.setSuccessful(false);       prev.setResponseMessage("Invalid response. Expected a valid JSON."); } 
+4
source

All Articles