Jmeter JSON Path Assertion
For start following JSONPath Assertion will test your statusCode
$.statusCode
put 200
to Expected Value of JSONPath Assertion.
This one is for userName
$.responseData.userName
Easy, isn't it? See Parsing JSON guide for more useful examples and how-tos.
I found the JSR223 Assertion with script language javascript
to be the easiest. at least if you have knowledge in java and javascript. And no need to add any plugins.
My working code in detail:
var json = JSON.parse(SampleResult.getResponseDataAsString());if (json.statusCode != 200) { AssertionResult.setFailureMessage("" + json.statusCode + " " + json.statusMessage + " " + json.errorMessage); AssertionResult.setFailure(true);}
I personally prefer to use BSF PostProcessor in coupling with Groovy language. Example of how to parse JSON with Groovy you can find here how to parse json using groovy