> For the complete documentation index, see [llms.txt](https://docs.avoautomation.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.avoautomation.com/avo-assure/actions/apis/assertion/jsonpath-match.md).

# JSONPath

This is a pre-built action available under **@Assertion** element type. This Action validates whether the value extracted from the JSON response using an JSONPath expression matches the expected value or regex pattern. The action supports different match types to validate the extracted value.

{% hint style="info" %}
**Note**: An API request must be added and executed successfully before configuring or evaluating API Assertions.
{% endhint %}

## Syntax

**Input Value**: `<JSONPath expression>;<Expected value/Regex pattern (optional)>;<Match type (optional)>`&#x20;

{% hint style="info" %}
**Note**: You can generate expressions automatically using the [Assertion expression builder](broken://pages/1lIlPX2iA6kojibGGuNs) available for the Response JSON Body. The generated expression can be used directly as the input for the JSONPath action.
{% endhint %}

| Argument                                   | Description                                                                                                                                                                                                                                                                                                                                                               |
| ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \<JSONPath expression> (Required)          | Specify the JSONPath expression used to extract the value from the JSON response.                                                                                                                                                                                                                                                                                         |
| \<Expected value/Regex pattern (optional)> | Specify the expected value or regex pattern to compare with the extracted value.                                                                                                                                                                                                                                                                                          |
| \<Match type (optional)>                   | <p>Specify the type of matching to perform between the extracted value and the expected value, regex pattern or different match types.<br><strong>Supported Match Types</strong>: Equals, Not Equals, Contains, Not Contains, Regex, Exist, Not Exist, Null, Not Null, Greater Than, Greater Than Or Equal, Less Than, Less Than Or Equal, Between, Data Type, Count.</p> |

**Output Value**: `<Actual value(optional)>;<Keyword Status(optional)>`

| Argument                                  | Description                                                                                                |
| ----------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| <p>\<Actual value></p><p>(optional)</p>   | The actual value stores the value extracted from the API response using the specified JSONPath expression. |
| <p>\<Keyword Status></p><p>(optional)</p> | The keyword status variable stores the status as **True** or **False**.                                    |

## Example 1: Validating a JSON Value

In this example, we verify that a value extracted from the API response matches the expected value.

* **Action:** JSONPath
* **Input Value:** $.company.name;TechsNova;Equals
  * The first part (**$.company.name**) specifies the JSONPath expression used to extract the value from the API response.
  * The second part (**TechsNova**) specifies the expected value.
  * The third part (**Equals**) validates whether the extracted value exactly matches the specified expected value.
* **Output Value**: {Actual Value};{Keyword Status}
  * The first output variable **{Actual Value}** stores the value extracted from the API response.
  * If the second output variable **{Keyword Status}** is defined, it stores the assertion result with the following possible values:
    * **True:** If the extracted value matches the expected value.
    * **False:** If the extracted value does not match the expected value.
* **Logical Explanation:** The **JSONPath** action evaluates the JSONPath expression (**$.company.name**) against the API response and extracts the value **TechsNova**. The extracted value is stored in the **{Actual Value}** variable. The action then compares the extracted value with the expected value (For example, **TechsNova**). If both values match, **{Keyword Status}** stores **True**; otherwise, it stores **False**.

<figure><img src="https://2174257472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fk8QZzXZMIJSStKAzDSTu%2Fuploads%2FYeZrvNSaT1BiHfQrSMXa%2Fimage.png?alt=media&amp;token=45d62531-e81f-47dc-ac5f-6d425996ad72" alt=""><figcaption></figcaption></figure>

## Example 2: Validating a Filtered JSON Value

{% hint style="info" %}
**Note**: To use a filter JSON expression, you must add it manually.
{% endhint %}

In this example, we verify the employee count for the branch located in Bengaluru using a JSONPath filter.

* **Action:** JSONPath
* **Input Value**: $.company.locations.branches\[?(@.city=="Bengaluru")].employees;120;Equals
  * The first part (**$.company.locations.branches\[?(@.city=="Bengaluru")].employees**) specifies the JSONPath filter expression.
    * **?()** defines the filter expression.
    * **@.city=="Bengaluru"** filters the branch whose city is Bengaluru.
    * **.employees** extracts the employee count from the matching branch.
    * **Equals** validates whether the extracted value exactly matches the specified expected value.
  * The second part (**120**) specifies the expected value.
* **Output Value:** {Actual Value};{Keyword Status}
  * The first output variable **{Actual Value}** stores the value extracted from the API response.
  * If the second output variable **{Keyword Status}** is defined, it stores the assertion result with the following possible values:
    * **True:** If the extracted value matches the expected value.
    * **False:** If the extracted value does not match the expected value.
* **Logical Explanation**: The **JSONPath** action evaluates the filter expression against the API response and locates the branch whose city is **Bengaluru**. It extracts the corresponding employee count (For example, **120**) and stores it in the **{Actual Value}** variable. The action then compares the extracted value with the expected value (For example, **120**). If both values match, the variable **{Keyword Status}** stores the value as **True**.

<figure><img src="https://2174257472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fk8QZzXZMIJSStKAzDSTu%2Fuploads%2Fwgqh9VzEqqns5NGLMtnn%2Fimage.png?alt=media&amp;token=e6405513-51d1-49da-aa50-5a22ab4bae4a" alt=""><figcaption></figcaption></figure>

## Supported JSONPath Expressions

| Symbol          | Meaning                            | Example                          | Purpose                                                                   | Returns                 |
| --------------- | ---------------------------------- | -------------------------------- | ------------------------------------------------------------------------- | ----------------------- |
| $               | Root JSON                          | $                                | To reference the root of the JSON document.                               | Entire JSON object      |
| .               | Child property                     | $.company.name                   | To access a child property of a JSON object.                              | TechNova                |
| \['key']        | Property with spaces/special chars | $.company\[‘first name’]         | To access a property whose name contains spaces or special characters.    | John                    |
| \[0]            | Array index                        | $.branches\[0].city              | To access an element at a specific array index.                           | Bengaluru               |
| \[-1]           | Last array element                 | $.branches\[-1].city             | To access the last element in an array.                                   | Hyderabad               |
| \[0,1]          | Multiple indices                   | $.branches\[0,1]                 | To access elements at multiple specified array indices.                   | First & second elements |
| \[1:3]          | Array slice                        | $.languages\[1:3]                | To access a range of array elements.                                      | Subset of array         |
| \[0:5:2]        | Slice with step                    | $.languages\[0:5:2]              | To access array elements within a range using a specified step value.     | Every 2nd element       |
| \[\*]           | Wildcard                           | $.branches\[\*].city             | To access all elements in an array or all matching child properties.      | All city values         |
| .\*             | All child properties               | $.company.\*                     | To access all child properties of an object.                              | All child values        |
| ..              | Recursive descent                  | $..city                          | To recursively search for a property throughout the JSON document.        | Every city in JSON      |
| \[?(condition)] | Filter                             | $.branches\[?(@.employees>100)]  | To filter array elements based on one or more conditions.                 | Matching objects        |
| &&              | Logical AND                        | @.city=='A' && @.employees>100   | To combine multiple conditions where all conditions must be true.         | Both conditions true    |
| \|\|            | Logical OR                         | @.city=='A' \|\| @.employees>100 | To combine multiple conditions where at least one condition must be true. | Either condition true   |
| == != > < >= <= | Comparison operators               | @.employees>=100                 | To compare values within a filter expression.                             | Comparison              |

#### **Knowledge Bites**

Here are some examples of different JSONPath assertion match types:

| Match Type            | Input Value                                      | Result                                                                 |
| --------------------- | ------------------------------------------------ | ---------------------------------------------------------------------- |
| Equals                | `$.data.address.zip;10010;Equals`                | Passes if the extracted value equals `10010`                           |
| Not Equals            | `$.data.address.zip;10011;Not Equals`            | Passes if the extracted value is not `10011`                           |
| Contains              | `$.data.address.city;New York;Contains`          | Passes if the extracted value contains `New York`                      |
| Not Contains          | `$.data.address.city;India;Not Contains`         | Passes if the extracted value does not contain `India`                 |
| Regex                 | `$.data.address.city;^[A-Za-z ]+$;Regex`         | Passes if the extracted value matches the specified regex pattern      |
| Exist                 | `$.data.email;;Exist`                            | Passes if the specified JSONPath returns a value                       |
| Not Exist             | `$.data.test;;Not Exist`                         | Passes if the specified JSONPath does not return a value               |
| Null                  | `$.data.name;;Null`                              | Passes if the extracted value is `null`                                |
| Not Null              | `$.data.address;;Not Null`                       | Passes if the extracted value is not `null`                            |
| Greater Than          | `$.data.address.zip;10009;Greater Than`          | Passes if the extracted value is greater than `10009`                  |
| Less Than             | `$.data.address.zip;10013;Less Than`             | Passes if the extracted value is less than `10013`                     |
| Greater Than or Equal | `$.data.address.zip;10010;Greater Than or Equal` | Passes if the extracted value is greater than or equal to `10010`      |
| Less Than or Equal    | `$.data.address.zip;10010;Less Than or Equal`    | Passes if the extracted value is less than or equal to `10010`         |
| Between               | `$.data.address.zip;100-100000;Between`          | Passes if the extracted value falls within the range `100` to `100000` |
| Data Type             | `$.data.address.city;String;Data Type`           | Passes if the extracted value is of the specified data type            |
| Count                 | `$.data.address.street[*];3;Count`               | Passes if the JSONPath returns `3` matching elements                   |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.avoautomation.com/avo-assure/actions/apis/assertion/jsonpath-match.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
