> OctoPerf load testing - JMESPath Variable Extractor documentation page. JMESPath Variable Extractors lets you extract variables from server JSON responses.

Source: https://api.octoperf.com/doc/design/edit-virtual-user/action-types/post-processors/jmespath-variable-extractor/

# JMESPath Variable Extractor

JMESPath Extractors lets you **extract values from HTTP JSON response bodies**, using <a href="https://jmespath.org" target="_blank" rel="noreferrer">JMESPath expressions</a>.

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.

![JMESPath ](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/post-processors/img/jmes.png "JMESPath 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.](#debug)                                                                                                                             |
| Path          | The JMESPath to be used. We recommend creating it with the [configure button](#configure). The path can contain 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 JMESPath having several results (or occurrences). Selecting **All** will change the behavior of your regex processor, see [the dedicated section](#multiple-occurrences) for more details. |

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

## Configure

The ![configure](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/post-processors/img/configure-button.png){ .off-glb } button or the ![configure](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/post-processors/img/configure-icon.png){ .off-glb } icon opens a new window in which you can use our JMESPath creator:

<video autoplay loop muted>
  <source src="https://api.octoperf.com/doc/design/edit-virtual-user/action-types/post-processors/img/configure-jmes.webm" type="video/webm">
</video>

!!! tip
    You can search for Strings or JMESPath 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 JMESPath. Make sure to check it every time you make a significant change:

![debug-processor](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/img/debug-processor.png)

The selected variable is shown in full under the table, with **Copy value** and **Copy name**: see [Read and copy a value](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/post-processors/regexp-variable-extractor/#read-and-copy-a-value).

### Multiple occurrences

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

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

![json-multiple-occurrence](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/post-processors/img/jmes-multiple-occurrence.png)

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

* `WorkspaceName_N` : the Nth value extracted,
* `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](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/logic-actions/foreach-action/) or [some functions](https://api.octoperf.com/doc/design/edit-virtual-user/functions/#__v) are a good way to deal with this in a dynamic context.

!!! warning
    Due to the way JMESPath 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 possible to use another variable in the JMESPath. In that case make sure to specify the value of this variable in the debug panel in order to see the expected result:

![json-path-variable](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/post-processors/img/jmes-path-variable.png)

### Example

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

```JSON
[
    {
        "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 JMESPath:

- `@`
- `@[*]`

For other examples and more resources check the [JMESPath documentation](https://jmespath.org/examples.html).
