1. Home
  2. ...
  3. Functions and Expressions
  4. JSONPath Expression

JSONPath Expression

See how to create a JSONPath expression

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.

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.

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.

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

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:

NOTE

Modified and expanded structure from Stefan Goessner.

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.

How happy are you with this page?

We use cookies to enhance your experience on our site. By continuing to browse, you agree to our use of cookies.Learn more