JSON Extractor

JMeter – JSON Extractor

Values from a JSON response are extracted using JMeter’s JavaScript Object Notation (JSON) Extractor. Actually, JSON is just a plain text format used to send data between a client and a server. It is created using a JavaScript object. As REST API usage increases, JSON is becoming the dominant data exchange format.

JSON Extractor can be used to extract the values from a JSON response and send them to another request in a JMeter script. A post processor. As I described in my last article, the post processor starts after the response from the server and performs tasks like getting the dynamic value, among other things. The behavior of the JSON extractor is the same. Let’s try to understand how it works.

How to add ‘JSON Extractor’?

Follow the below steps:

  1. Select the ‘Sampler’ element whose response contains JSON value and you want to capture
  2. Right-click on the sampler
  3. Hover the cursor on ‘Add’
  4. Hover the cursor on ‘Post Processors’
  5. Click ‘JSON Extractor’

What are the ‘JSON Extractor’ input fields?

There are the following input fields for “JSON Extractor”:

Name: To indicate the name of the post-processor

Feedback – To provide random feedback, if any.

Use to: Define dynamic value lookup parameters.

Subsamples and the main sample: Use this search scope if the request is redirected so that the required JSON value can be searched in both the main response and the response of the redirected request.

parent example only: Use this search scope if the request is not redirected or if the JSON value is only included in the response to the original request.

Subexamples only: You can use this search scope when a request is redirected and the required JSON value is returned in the response to the redirected request.

Convenience JMeter variable name: Select this option and enter the name of the JMeter variable in the text field if the JSON value is to be retrieved from the value of any JMeter variable.

Newly formed variable name: The names of the variables that contain the required JSON values. These are called “JSON Extraction Variables“. The names of the variables that contain the output of the JSON-PATH expressions must be separated by a semicolon. The number must match the number of JSON-PATH expressions.

Path expressions in JSON The JSON path expression must be entered here. More than one JSON path expression can be written and they must be separated by semicolons. Due to the synchronization between JSON variables and JSON path expressions, the first value is always assigned to the first variable.

Match number (0 for random): If more than one string matches in the response data and you need to use the value of the JSON variable that appears in a specific position (say second place), you should specify 2. JMeter recognizes all matching values on the page, but stores only the second value in the variable. It is identical to the LoadRunner ordinal. While ‘0’ selects a random value from the list of dynamic match values, ‘-1’ is used to capture all values. The required value can be used as variable name>_1, variable name>_2, etc. after extracting all values using -1.

Concatenation var calculation (suffix_ALL): This choice is indicated. JMeter then uses the ‘,’ character to concatenate all the values and stores the result in the _ALL variable.

Default Value – The default value (for example, JSON_value_Not_Found) can be set if the JSON path expressions do not match. It is very useful for debugging scripts.

Using an example to learn:

Consider the following values in the JSON response. If I want to capture all the values for “size” and “price”, I enter $..size;$..prize in the JSON Path Expression box and the values are stored in the variables varSize and varPrize respectively .

{

    “shop”: {

        “cloth”: [

            {

                “category”: “male”,

                “type”: “shirt”,

                “size”: 40,

                “price”: 800

            },

            {

                “category”: “male”,

                “type”: “jeans”,

                “size”: 32,

                “price”: 1699

            },

{

                “category”: “female”,

                “type”: “top”,

                “size”: 32,

                “price”: 699

            },

            {

                “category”: “female”,

                “type”: “jeans”,

                “size”: 28,

                “price”: 2999

            }

        ],

        “shoe”: {

            “color”: “black”,

“size”: 7,

            “price”: 2599

        }

    },

    “tax”: 99

}

JMeter - JSON Extractor
Scroll to Top