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.
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 |
---|---|---|
|
|
returns the books from the fiction category. |
|
|
returns the books whose author isn’t J. R. R. Tolkien. |
|
|
returns the books released after 1980. |
|
|
returns the books released in or after 2000. |
|
|
returns the books that cost less than 10. |
|
|
returns the books that cost less or exactly 10. |
|
|
returns the books that belong to a category beginning with "fic". |
|
|
returns the books that don’t have an isbn number. |
|
|
returns the books from the fiction category and that cost less than 10. |
(logical operator OR) |
|
returns the books from the fiction category or that cost less than 10. |
|
|
returns the movies in the documentary category. |
|
|
returns the movies that aren’t in the fantasy category. |
|
|
returns fantasy movies, in case fantasy is a subset of movie categories. |
|
|
returns the title "Moby Dick", if it exists amongst the titles available. |
|
|
returns book titles with 9 characters, including spaces. |
|
|
returns books whose isbn is an empty value. |
|
|
returns the books whose isbn is not an empty value. |
Share your suggestions with us!
Click here and then [+ Submit idea]