JSONPath Expressions¶
Note
WSO2 Micro Integrator will continue to support existing JSONPath expressions. However, it is recommended to use the new Synapse Expressions, as they simplify data extraction and provide a rich set of functions.
JSONPath expressions are used for navigating and querying JSON data. JSONPath allows you to extract specific data from JSON documents.
JSONPath expressions are used within mediators like Log, Filter, Property, and Switch mediators to extract JSON data.
json-eval
function in expressions is used to specify JSONPath.
- The syntax usually starts with
$
to represent the root of the JSON document. - Dots (.) and brackets ([]) are used to traverse different levels of the JSON hierarchy.
JSONPath syntax¶
Suppose we have the following payload:
{
"id": 12345,
"id_str": "12345",
"array": [ 1, 2, [ [], [{"inner_id": 6789}] ] ],
"name": null,
"object": {},
"$schema_location": "unknown",
"12X12": "image12x12.png"
}
The following table summarizes sample JSONPath expressions and their outputs:
Expression | Result |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
You can evaluate a JSONPath expression against a property that contains a JSON payload using Variables.
To evaluate a JSONPath expression against a property, use the following syntax.
json-eval(<scope_of_the_property>:<property_name>.<JSONPath_expression>)
Example 1: When the property is in the default scope you can use $ctx.
json-eval($ctx:propertyName.student.name)
Example 2: When the property is in the Axis2 scope you can use $axis2.
json-eval($axis2:propertyName.student.name)
Example 3: When the property is in the transport scope you can use $trp.
json-eval($trp:propertyName.student.name)