---
title: JSONPath Expression
description: See how to create a JSONPath expression
documentId: ipaas-legacy-jsonpath
locale: en-US
---

The condition informs the path that the integration flow should follow when the information described there appears in the *body* of the request/response *payload* of the *step* preceding **Choice V2**.

To define the condition, you must use a **JSONPath** expression.

<Callout type="note" title="NOTE">
JSONPath is a query language for JSON that allows you to select and extract data from a JSON document. 
You use a JSONPath expression to traverse the path to an element or set of elements in the JSON structure.
</Callout>

In the image below, the condition described for **WHEN** indicates that if the "city" element equals "São Paulo", the flow should follow that path. 
If the information is different from this, the flow will follow another path defined in another **WHEN** condition or **OTHERWISE**.

![](https://creative-ball-51b3fc85c0.media.strapiapp.com/condition_example_city_27e06b8014.png)

Now imagine you have the response *payload* from a previous *step* with the following information:

```json
{
    "city": "São Paulo"
}
```

Thus, since the *payload* has the city element information equal to São Paulo, the flow will follow the path indicated in the **WHEN** condition, as seen in the image.  

## JSONPath syntax rules

To better understand the composition of a condition, let's look at the main syntax rules for JSONPath expressions: 

* The "$" symbol refers to the root object or element.
* The "@" symbol refers to the current object or element.
* The "." operator is used to denote a child element of the current element.
* "[ ]" is used to denote a child element of the current element (by name or index).
* The "*" operator is a wildcard character, returning all objects or elements regardless of their names.
* The "," operator is the union operator, which returns the union of indicated children or indexes.
* The ":" operator is the operator for selecting parts of *arrays*.
Thus, it returns a sub-collection from a collection.
* "? ( )" is used to filter all items that meet a certain criterion.

## Usage examples

Now see examples of expressions, based on the JSON structure below: 

<Callout type="note" title="NOTE">
Modified and expanded structure from [Stefan Goessner](https://goessner.net/articles/JsonPath/).
</Callout>

```json
{
    "store": {
        "book": [
            {
                "category": "non-fiction",
                "author": "Jane Glover",
                "title": "Mozart in Italy",
                "price": 8.95,
                "year": 2023
            },
            {
                "category": "fiction",
                "author": "Herman Melville",
                "title": "Moby Dick",
                "isbn": "0-553-21311-3",
                "price": 8.99,
                "year": 1851
            },
            {
                "category": "fiction",
                "author": "J. R. R. Tolkien",
                "title": "The Lord of the Rings",
                "isbn": "0-395-19395-8",
                "price": 22.99,
                "year": 1954
            }
        ],
        "movie": [
            {
                "category": "TV series",
                "author": "David Crane and Marta Kauffman",
                "title": "Friends season 1",
                "price": 50,
                "year": 1995
            },
            {
                "category": "documentary",
                "author": "Craig Mazin",
                "title": "Chernobyl",
                "price": 35,
                "year": 2019
            },
            {
                "category": "fantasy",
                "author": "J. R. R. Tolkien",
                "title": "The Lord of the Rings",
                "price": 40,
                "year": 2001
            }
        ]
    }
}
```

| Operators | Expression | Meaning |
|---|---|---|
| `==` (equal) | `$.store.book[?(@.category == "fiction")]` | returns books in the fiction category. |
| `!=` (not equal to) | `$.store.book[?(@.author != "J. R. R. Tolkien")]` | returns books whose author is not J. R. R. Tolkien. |
| `>` (greater than) | `$.store.book[?(@.year > 1980)]` | returns books released after 1980. |
| `>=` (greater than or equal to) | `$.store.book[?(@.year >= 2000)]` | returns books released in or after the year 2000. |
| `<` (less than) | `$.book[?(@.price < 10)]` | returns books with a price less than 10. |
| `<=` (less than or equal to) | `$.store.book[?(@.price <= 15)]` | returns books with a price less than or equal to 15. |
| `=~` (matches JavaScript RegEx) | `$.store.book[?(@.category =~ /fic.*/i)]` | returns books that belong to a category starting with "fic". |
| `!` (negates the filter) | `$.store.book[?(!@.isbn)]` | returns books that do not have an isbn number. |
| `&&` (logical AND operator) | `$.store.book[?(@.category=="fiction" && @.price < 10)]` | returns books in the fiction category with a price less than 10. |
| `\|\|` (logical OR operator) | `$.store.book[?(@.category=="fiction" \|\| @.price < 10)]` | returns books in the fiction category or with a price less than 10. |
| `in` | `$.store.movie[?(@.category in ["documentary"])]` | returns movies that are in the documentary category. |
| `nin` | `$.store.movie[?(@.category nin ["fantasy"])]` | returns movies that are outside the fantasy category. |
| `subsetof` | `$.store.movie[?(["fantasy"] subsetof @.category)]` | returns fantasy movies if fantasy is a subset of the movie categories. |
| `contains` | `$.store.book[?(@.title contains "Moby Dick")]` | returns the title "Moby Dick" if it exists among the available titles. |
| `size` | `$.store.book[?(@.title size 9)]` | returns book titles that have 9 characters, including spaces. |
| `empty true` | `$.store.book[?(@.isbn empty true)]` | returns books that have isbn as an empty value. |
| `empty false` | `$.store.book[?(@.isbn empty false)]` | returns books that have isbn as a non-empty value. |
