Using JSON Extractor in Jmeter to Extract and Re-Use the values in the script

Using JSON Extractor in Jmeter to Extract and Re-Use the values in the script

Using JSON Extractor in Jmeter to Extract and Re-Use the values in the script. 

The tutorial below will help you, if you are working in a Microservices architecture and calling multiple end points within various customer journeys. 

Version of Jmeter: 5.1 

For me always an example-based approach has worked and I would like to share an example to showcase the working of this. 

Below is the response of an end point and id & type need to be passed in the subsequent requests. 

"type": "XXXXXXXXXX", 

" id": "ABC123456", 

"token": "FfYWUSBSUE343423432asjkjad0000oooowwwUUU" 

Instead of using a Regex or bean shell scripting, we have a plugin JSON Extractor which makes our life very very easy. 

Check out the screenshot of the plugin below 

No alt text provided for this image

Let’s see the definition of every field 

Name: Name as seen in the reports/response 

Comments: Mention here for any information to the user 

Apply to: Based on what is selected 

  1. Main sample and sub-samples: - The fetched values can be used globally in the script. 
  2. Main Sample only: - The fetched values can be used only in the main sample. 
  3. Sub-sample only: - The fetched values can be used only in the Sub sample. 
  4. Jmeter Variable Name to use: - If a variable name is declared that can be used. 

Name of Created Variable: This is where we need to enter the name of variable in which we want the fetched value to be stored. 

There is a specific way to mention multiple variables which need to be fetched. You can view in the below screenshot, how! 

Json Path Expressions: This is where the script is written to extract the value from the response. 

Match No.: If there are multiple values for the same parameter, specify which one is needed or just leave it blank. 

Compute concatenation var(suffix_ALL): This option if checked adds a suffix. 

Default Values: These are the values which will be stored in the created variables if the response is incorrect. 

Important point to note is that the number of Created variables and Default values always have to be same. If not, there would be an error. 

Checkout the filled values in the plugin below for the above response. 

No alt text provided for this image

How to Re-Use? 

It is very simple now, if the values are extracted and let’s say in a request fetched value of id needs to be passed. 

Next Request would be like: 

"Id2”: "${id}" 


To view or add a comment, sign in

More articles by Nilesh Gupta

  • While Controller and Why is it needed?

    In today`s Microservices architecture, when calling services, we do not expect an instant answer from them. It is quite…

Explore content categories