Skip to content

JSONPath Variable Extractor

JSONPath Extractors lets you extract values from HTTP JSON response bodies, using JSONPath 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

Field Description
Name Name of the variable created by this processor. Can be used with the ${...} syntax like any other variable.
Usage Usage example of this variable. A click on Extracted variables opens the debug panel.
Path The JSONPath to be used. We recommend creating it with the configure button. The path can be a variable but cannot contain text AND a variable.
Default value If no value is found, the variable will be equal to this. With match number All, you get the default value if you do not provide an index number.
Match number Lets you choose how to deal with the JSONPath having several results (or occurrences). Selecting All will change the behavior of your regex processor, see the dedicated section for more details.
Concatenate Results In case Match Number All is selected, this concatenate all matching values in a comma-separated list. The result is stored in a dedicated variable with the suffix _ALL.

Info

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

Configure

The configure button or the configure icon opens a new window in which you can use our JSONPath creator:

configure-json.gif

Tip

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

Debug

Simple

Opening the debug panel allows you to quickly see the result of your JSONPath. Make sure to check it every time you make a significant change:

debug-processor

Multiple occurrences

When the match number is set to all, the behavior of your JSONPath extractor changes.

Instead of a single variable, a lot of variables are created:

json-multiple-occurrence

Even if there is only one occurrence, the general structure of multiple occurrences extractions will always be:

  • WorkspaceName_N : the Nth value extracted,
  • WorkspaceName_ALL : all occurrences concatenated in a comma separated list,
  • WorkspaceName_matchNr : the number of values extracted, e.g. 4.

This means that you will have to provide an index when using this variable, typically the Foreach action or some functions are a good way to deal with this in a dynamic context.

Warning

Due to the way JSONPath 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.

Variable

It is not possible to use a variable inside a JSONPath string. Instead you need to replace the entire expression with a variable, otherwise the variable name syntax may conflict with the JSONPath syntax.

json-path-variable

Example

For instance in a situation like this you might want to get all the workspace names in the list:

[
    {
        "id": "629WW7T4pwtaiecauWi4PasdaQruHr",
        "name": "Templates",
        "userId": "user-42"
    },
    {
        "id": "QMSQSdFVkcQ4q4ktTVqeYXS7nVvEy9",
        "name": "Shared Providers",
        "userId": "user-42"
    },
    {
        "id": "K62vyCX2cymazgFH2bfkju6eNKUTYR",
        "name": "Demo",
        "userId": "user-42"
    },
    {
        "id": "XQ4PVBN3w7tmzf9r2Az8KsDeK4q3EZ",
        "name": "This is a test",
        "userId": "user-42"
    }
]

To that end we can use one of the following JSONPath:

  • $[*]['name']
  • $..name