Creating a JSONPath expression

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

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

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 navigate the path to an element or set of elements in the JSON structure.

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

condition example city

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

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

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

JSONPath syntax rules

To better understand the composition of a condition, let’s see 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, returning all objects or elements regardless of their name.

  • The "," operator is the union operator, which returns the union of the indicated children or indexes.

  • The ":" operator is the operator for selecting parts of arrays. Thus it returns a subcollection of a collection.

  • "? ( )" is used to query all items that meet a certain criteria.

Usage examples

Now, let’s check some examples of expressions, based on the JSON structure below:

Stefan Goessner’s modified and expanded structure.
 {
    "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 to)

$.store.book[?(@.category == "fiction")]

returns the books from the fiction category.

!= (different than)

$.store.book[?(@.author != "J. R. R. Tolkien")]

returns the books whose author isn’t J. R. R. Tolkien.

> (greater than)

$.store.book[?(@.year > 1980)]

returns the books released after 1980.

>= (greater or equal to)

$.store.book[?(@.year >= 2000)]

returns the books released in or after 2000.

< (less than)

$.book[?(@.price < 10)]

returns the books that cost less than 10.

(less or equal to)

$.store.book[?(@.price ⇐ 15)]

returns the books that cost less or exactly 10.

=~ (compatible with RegEx JavaScript)

$.store.book[?(@.category =~ /fic.*/i)]

returns the books that belong to a category beginning with "fic".

! (denies the filter)

$.store.book[?(!@.isbn)]

returns the books that don’t have an isbn number.

&& (logical operator AND)

$.store.book[?(@.category=="fiction" && @.price < 10)]

returns the books from the fiction category and that cost less than 10.

logical or (logical operator OR)

$.store.book[?(@.category=="fiction" logical or @.price < 10)]

returns the books from the fiction category or that cost less than 10.

in

$.store.movie[?(@.category in ["documentary"])]

returns the movies in the documentary category.

nin

$.store.movie[?(@.category nin ["fantasy"])]

returns the movies that aren’t in the fantasy category.

subsetof

$.store.movie[?(["fantasy"] subsetof @.category)]

returns fantasy movies, in case fantasy is a subset of movie categories.

contains

$.store.book[?(@.title contains "Moby Dick")]

returns the title "Moby Dick", if it exists amongst the titles available.

size

$.store.book[?(@.title size 9)]

returns book titles with 9 characters, including spaces.

empty true

$.store.book[?(@.isbn empty true)]

returns books whose isbn is an empty value.

empty false

$.store.book[?(@.isbn empty false)]

returns the books whose isbn is not an empty value.

Thanks for your feedback!
EDIT

Share your suggestions with us!
Click here and then [+ Submit idea]