JSONPath is a query language for JSON, the JSON equivalent of XPath for XML. It lets you select nodes from a JSON document with a compact path expression. After years of incompatible implementations, IETF RFC 9535 (2024) standardised the syntax. This reference lists the standard segments and selectors with examples.
How it works
Every JSONPath starts at the root identifier $. You then chain segments that
each narrow or expand the set of selected nodes: .name or ['name'] for a
child, [*] for every element, .. to descend into all descendants, [0] or
[1:3] for array indices and slices, and ?<expr> to filter. Inside a filter,
@ refers to the item currently being tested. The engine evaluates the path
left to right, producing a node list.
Worked example
Given this document:
{ "store": { "books": [
{ "title": "A", "price": 8 },
{ "title": "B", "price": 15 }
] } }
$.store.books[*].titleselects["A", "B"]$..priceselects[8, 15](recursive descent)$.store.books[[email protected] < 10].titleselects["A"](filter)
Notes and tips
Recursive descent .. is convenient but scans the whole subtree, so prefer an
explicit path on large documents. Filter comparisons are type-aware: comparing a
string to a number is simply false rather than an error. Use length() and
count() function extensions for size-based filters, e.g.
$.items[?length(@.tags) > 0].