JSON Path Transformer V2
Discover more about the JSON Path Transformer V2 component and how to use it on the Digibee Integration Platform.
JSON Path Transformer V2 has the function of receiving any valid JSON input and making filters and data extractions from an expression. This version of the component also supports Double Braces expressions.
JSONPath is a consulting language for JSON with resources similar to XPath. This expression is normally used to select and extract property values from a JSON object. Learn more in the documentation about JSONPath.
Parameters
Take a look at the configuration options for the component. Parameters supported by Double Braces expressions are marked with (DB)
.
Parameter | Description | Default value | Data type |
---|---|---|---|
JSON Path | Used to show which expression will be used when processing JSON. It's a mandatory parameter and must be configured according to what you want to process. A Double Braces expression can be used to obtain the JSON Path value dynamically from the input. | $.store.books[?(@.title=='IT')] | String |
Fail On Error | If the option is activated, the execution of the pipeline with an error will be interrupted; otherwise, the pipeline execution proceeds, but the result will show a false value for the “success” property. | False | Boolean |
See a list of options for declaring JSONPath:
$: object root or vector.
.property: selects a specific property in the related object.
['property']: selects a specific object in the related object. Use single quotes only around the property name. Tip: keep this instruction in mind if the property name has special characters, such as spaces, or if it starts with characters different than A..Za..z_.
[n]: selects the n element of a vector. The indexes start with 0.
[index1,index2,…]: selects elements from the vector with specific indexes and returns a list.
..property: descending recursive. It makes a descending search in property names and returns a vector of all the values with this property name. It always returns a list, even if only 1 property is found.
: the asterisk selects all the elements in an object or vector, whatever their names or indexes are. For example, “address.” means all the properties of the object address, while “book[*]” means all the items of a book vector.
[input:output] / [input:]: selects elements from an input vector and even, but not necessarily, an output vector. If the output is omitted, select all the vectors until the end of the vector. A list is returned.
[:n]: selects the first n elements of the vector. A list is returned.
[-n:]: selects the last n elements of the vector. A list is returned.
[?(expression)]: filter expression. It selects all the elements in an object or vector that match with the specified filter. A list is returned.
[(expression)]: script expressions can replace explicit names from properties or indexes. For example, [(@.size-1)], that selects the last items of a vector. Here, the size refers to the vector size in question more than a JSON file named "size".
@: used in filter expressions to make reference to the current joint that is being processed.
==: equal to .1 and '1' are considered the same result. String values must be attached in single quotes (and not in double quotes): [?(@.cor=='vermelho')].
!=: different than. String values must be attached in single quotes.
>: greater than.
>=: greater than or equal to.
<: smaller than.
<=: smaller than or equal to.
=~: compatible with a regular RedEx Java Script. For example, [?(@.description =~ /cat.*/i)] matches items whose description starts with cat (upper and lowercase aren't considered).
!: used to deny a filter. For example, [?(!@.isbn)] matches items that don't have the isbn property.
&&: AND logical operator. Example: [?(@.category=='fiction' && @.price < 10)]
||: OR logical operator. Example: [?(@.category=='fiction' || @.price < 10)]
Messages flow
Input
To show the functionality of this component, you must configure an input JSON in a pipeline with JSON Path Transformer V2. After adding it to the pipeline, it's necessary to configure the JSONPath expression as $.address..[?(@.postalCode == '02375')].streetAddress or the example won't work.
The intention of this example is to filter the input addresses by one postal code only and return just the address street. See:
Output
The structure will be the JSON filtered by the JSONPath specification.
JSON Path Transformer V2 in action
Below you can see how the component responds to certain situations and how it is configured in each case.
Return the book authors only with a recursive descendant parser
In this example, you'll see only the authors of an array with books inside a store. The expression configuration of the component must be $..author.
Input
Output
Return products with a value lower than the one specified only
In this example, you'll see only the products of an array with prices lower than US$3,300. The expression configuration of the component must be $..[?(@.price<3300)].
Input
Output
Informing an invalid expression with the "Fail On Error: false" configuration
With this example you can configure the component with Fail On Error as “false” and use the expression $.
With these configurations, the result will be an error message and with the property "success": false
.
Input
Output
Informing an invalid expression with the "Fail On Error: true" configuration
With this example you can configure the component with Fail On Error as “true” and use the expression $.
With these configurations, the result will be an error message and the deployment will be immediately interrupted.
Input
Output
Returning only error results from an array input
In this example, only the error results are extracted from an array of executions. The expression configuration of the component must be $..[?(@.error)]
.
Input
Output
Obtain the JSON Path expression dynamically from the input
In this example, the JSON Path is dynamically obtained from the input using a Double Braces expression. The expression configuration of the component must be {{ message.jsonPath }}
.
Input
Output
Last updated