How To use JSON Extractor in Jmeter
Json extractor is used like regular expression extractor to capture some dynamic values from the response but used for json only.
By using this we can fetch the values of variables in the Json.
Let me take an example
Below is the Json and its corresponding response:
Here we want to extract the value of variable name "label" or "val"
which are changing dynamically
We can use Json extractor to fulfil thie purpose here
below is the JSON values that can be used
In this Json extractor blow are the parameters and their corresponding values
Variable Name: Name of the variable (can be used anything logical, here we have used the same as we are getting in response)
JSON Path expression: It is the most important part for JSON configurations, We should use the path extractor expression here.
Here we have used $..lable , Here two dot means we have json variable in two nested blocks, For normal JSON where there is only one tag , we used single dot.
Match Number: 0 means any random value, here we can use 1 or 2 to get first value or second value and so on, we can also use -1 for getting all possible values to be stored in array (with variable name as mentioned above)
Default Values: this values that can be passed when we didnt got the expected value.
TO varify the value captured in Json extractor:
We can use the Debug Sampler on the thread group to validate the value captured using Json extarctor, Debug sample is used to print all the used defined configured variable in jmeter.
Here we can see that variable "label": captured SpiceJet , and
lable_matchNr having value as 10 because there are 10 occurrence of the values
corresponding to the expression we have defined for variable label in JSON
extractor.
Feel
Free to add if i have missed anything.