Skip to content

Json Variable Extractor

JSon Extractors lets you extract values from HTTP JSON response bodies, using JSON path expressions.

Extracting variables from HTTP response helps you make your Virtual User have a dynamic behavior. Extracted variables can be injected in Logic Actions or HTTP Request Actions.

JSON Extractor

The first line displays the extracted variable name. This field is mandatory if you want to inject what you extract. The second line contains tab headers to access:

  • Simple Configuration, to easily generate a JSON path expression,
  • Advanced Configuration, for more specific needs,
  • Check, to validate the result of your JSON path against a recorded HTTP response.

Info

The response selector, on the right, lets you choose which HTTP response is used for configuring and checking the JSON Path Action. So if neither recorded responses nor Validate VU responses are available, you have to configure the JSON Path Action manually.

Simple configuration

The JSON Path Action is used to extract values from HTTP response formatted in JSON. The simple editor is only available if you have a recorded or check JSON response body on the enclosing HTTP Action.

To extract a value from a JSON response body :

  1. Select the Configuration tab,
  2. Browse the response body array, and select the line you want to extract,
  3. The generated JSON path expression is shown on the bottom of the tab, and can be edited in Advanced mode.

JSON Extractor Simple mode

Tip

You can search for Strings or JSON Path Expressions inside the response body using the search fields in the table headers.

Advanced configuration

You may start with the simple mode, and then switch to advanced to customise the generated JSON path expression.

The Advanced tab may fulfil more complex requirements.

JSON Extractor Advanced mode

The following procedure explains how to configure a JSON Path Action:

  1. Select the Advanced tab,
  2. Fill in the JSON Path field using JSON path syntax,
  3. Select the match number,
  4. Fill in the default value (if the regexp does not match the HTTP response),
  5. Select Concatenate results.

Tip

The response panel only displays the content of the HTTP response Body. To select the text to extract, use the simple Configuration tab.

Note

The match number format:

  • Random, to select any of the values.
  • Select nth, to select a particular value.
  • All, to select all values. If you select this option, the generated variable can be used in the ForEach Action.

The Concatenate results: If many results are found, this option concatenates them using ',' separator and stores it in a var named <variable name>_ALL. You can take a look at the Check tab to view the resulting variable value.

Check JSON path result

To check the result of a JSON path expression just click on the Check tab.

The check process is automatically launched when this tab is opened. It can also be manually started using the Refresh button.

A table contains the extracted values :

Column name Description
Extracted variable name The name of the extracted variable. A single JSON Path Action can lead to multiple extracted variables. More information below.
Extracted variable value The value of the extracted variable.

Note

Multiple variables can be generated by a single JSON Path Action.

E.g. using the following JSON body :

{ "store": {
    "book": [
      { "category": "categoryOne",
        "author": "Pierre Bordage",
        "title": "Les derniers hommes",
        "price": 10.55
      },
      { "category": "categoryTwo",
        "author": "Alain Damasio",
        "title": "La Zone du dehors",
        "price": 19.99
      }
    ]
}
}
For an extractor named author with the JSON path value $.['store']['book'][*]['author'] and a Select Nth match number:

  • author : the base variable, it contains the extracted value (or the default value), e.g. Pierre Bordage
  • author_matchNr : the number of results, e.g. 2.

With an All match number, multiple variables are generated to be used in the ForEach Action :

  • author_N : the Nth value extracted,
  • author_matchNr : the number of values extracted, e.g. 2,
  • author_ALL : if Concatenate results was also selected e.g. Pierre Bordage,Alain Damasio.

Warning

Due to the way JSON Path is processed inside the underlying JMeter, Nodes of the same level may be extracted in a different order than what is displayed in OctoPerf. This shouldn't be an issue since the structure will be the same anyway.