Is anyway to verify JSON Response got from RestFul API in JMeter?
I am getting below response:
{"workingfrom":[{"id":1234,"type":"office","name":"N1"},{"id":5678,"type":"home","name":"N2"}]}
Is anyway to verify JSON Response got from RestFul API in JMeter?
I am getting below response:
{"workingfrom":[{"id":1234,"type":"office","name":"N1"},{"id":5678,"type":"home","name":"N2"}]}
JSON Assertion is another way (in JMeter 4). It can easily assert whether or not a node was present. It can even assert on the node value (regex or otherwise).
Just put groovy-all-2.3.2.jar in the /lib directory of your JMeter installation and then you can use the Groovy JsonSlurper wrapper. After you start JMeter with that .jar in the path, then you can add a JSR223 Sampler that uses Groovy script.
Also, if you install the JMeter plugin packs, there is a JSON Path Extractor plugin, which has worked well for me.
These are 2 very nice alternatives to using regular expressions. If you are writing a lot of tests, either of these 2 methods will be superior.
You can use JMeter's JSON Plugins.
Install it first:
Now add it to your test plan (or thread group, etc.): Dropdown menu Add -> Assertions -> jp@gc - JSON Path Assertion
Then configure it:
Assuming that your data looks like {"version":"5.0.0","hitCount":23}
$.hitCount
23
Here is more information about JSON Path Assertion.
Add a Response Assertion and use a regex to validate the string. The regex you can use can be found elsewhere on Stackoverflow, here to be precise. Notice that this is a very costly operation and will probably eat your CPU if you do it with n concurrent threads.
You can create variable and use it inside JSR223 Assertion if you want to compare values with response values
String code = vars.get("NumberOfUnit");
if(code >= "250" || code <="1000"){
AssertionResult.setFailure(false);
}
else{
AssertionResult.setFailure("Error");
AssertionResult.setFailure(true);
}
Install JMeter Plugins Manager
Install JSON/YAML Plugins (deprecated)
I have similar json structure {"results": [{"types": [{"id":
and I tried $.types
without luck.
The correct JSON Path and value specification could be found in official documentation:
$.results[*].types
In your case, you could assert id
value by:
$.workingfrom[*].id