Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to verify JSON Response in JMeter?

Tags:

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"}]}
like image 544
Anand Somani Avatar asked Jun 25 '13 13:06

Anand Somani


People also ask

What is JSON extractor?

JSON Extractor- It is a handy tool to execute JSON Path expressions against JSON responses and storing the result into a JMeter Variable. If the response of any request is in JSON then we can use this extractor.

How pass JSON object in post request in JMeter?

To send a POST HTTP Request with the JSON Data inside the body, need to add, HTTP Header Manger into your request and set the name as 'content-type' and value as 'application/json' this will attached into HTTP request header and what ever the data inside your request body will send as json format.


2 Answers

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). enter image description here

like image 118
singh2005 Avatar answered Oct 16 '22 17:10

singh2005


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.

like image 43
djangofan Avatar answered Oct 16 '22 16:10

djangofan