JSONPath is a query language for picking values out of a JSON document, in the same spirit that XPath works for XML. It shows up in API tools, monitoring systems, Kubernetes, and test frameworks. It became an IETF standard (RFC 9535) in 2024, but many tools still implement slightly different dialects.
A sample document
{
"store": {
"books": [
{ "title": "A", "price": 8.95, "tags": ["new"] },
{ "title": "B", "price": 12.99 },
{ "title": "C", "price": 22.99 }
],
"owner": "Sam"
}
}The core syntax
- $ is the root of the document.
- .name or ['name'] selects a child by name: $.store.owner returns "Sam".
- [n] selects an array element by index: $.store.books[0].title returns "A".
- * is a wildcard: $.store.books[*].title returns every title.
- .. is recursive descent, searching at any depth: $..price returns every price anywhere.
- [start:end] slices arrays: $.store.books[0:2] returns the first two books.
- [?(@.price < 10)] filters items, where @ is the current element: $.store.books[?(@.price < 10)] returns books cheaper than 10.
Worked examples
- All titles: $.store.books[*].title gives A, B, C.
- Cheap books: $.store.books[?(@.price < 15)].title gives A and B.
- Books with tags: $.store.books[?(@.tags)] returns only book A.
- The last book: $.store.books[-1] in dialects that support negative indexes.
Dialect differences to watch
- Filter syntax varies: some tools require parentheses (?(...)), others accept ?(...) or just ?....
- Negative indexes, slices, and functions like length() are not supported everywhere.
- Behavior on missing keys differs: some tools return an empty result, others raise an error.
- String comparison and regex support in filters vary.
Frequently asked questions
+What does $.. mean in JSONPath?
$ is the root and .. is recursive descent, so $..name finds every 'name' key at any depth.
+How do I filter an array in JSONPath?
Use a filter expression such as [?(@.price < 10)], where @ refers to each element being tested.
+Is JSONPath the same as jq?
No. jq is a full command-line processor with its own language. JSONPath is a simpler query syntax that many tools embed.
+Is JSONPath standardized?
Yes. RFC 9535 was published in 2024, but older implementations may differ from it.
JSONPath Tester
Free, runs in your browser — nothing you enter is uploaded.