JSON Path
Several filters in the HTTP connector use JSON paths. This page explains what they are, and gives useful pointers.
What is a JSON path?
A JSON path is a textual expression that specifies one or more parts of a JSON document declaratively, much like XPath for XML.
In some Gallium Data filters, a JSON payload is available to your code as a JavaScript object, which is easy to read and modify using JavaScript code. However, sometimes, you may want to query a JSON document without writing procedural code.
If a JSON payload is:
{
"name": "Mary Smith",
"address": {
"street": "123 Main St",
"city": "Cleveland, OH",
"country": "USA"
},
"akas": ["J. Smith", "Mary Jane Smith", "M Jane", "MJ"]
}
then the following expressions would return:
$.address
{
"street": "123 Main St",
"city": "Cleveland, OH",
"country": "USA"
}
$.address.city
"Cleveland, OH"
$.akas[2]
"M Jane"
$.akas[?(@ =~ /.*Jane.*/)]
[
"Mary Jane Smith",
"M Jane"
]
Gallium Data uses the excellent JsonPath library to evaluate JSON paths. See that documentation for a complete description of all operators and functions.
Useful links
JSON Path examples: a number of examples
JSON Path evaluator: an online evaluator, useful to explore and debug JSON paths