JSONPath Cheat Sheet
JSONPath selects values from a JSON document. The expressions below were run against the engine used by the JSONPath tester, with a bookstore sample.
Operators
| Syntax | Meaning | Example |
|---|---|---|
$ | The root of the document | $ |
. or ['key'] | Child key (brackets for keys with spaces or dots) | $.store.book or $['store']['book'] |
[n] | Array item by index, starting at 0 | $.store.book[0] |
[*] or .* | Every child | $.store.book[*].author |
.. | Recursive descent: search at any depth | $..price |
[a,b] | Union of indexes or keys | $.store.book[0,2].title |
[start:end] | Slice, end excluded | $.store.book[0:2].title |
[-1:] | The last item (negative start in a slice) | $.store.book[-1:] |
Filters
Inside [?( )], @ is the item being tested. Strings must be quoted.
| Syntax | Meaning | Example |
|---|---|---|
[?(@.k < n)] | Compare a number | $.store.book[?(@.price < 10)].title |
[?(@.k == 'x')] | Compare a string | $.store.book[?(@.category == 'fiction')].title |
[?(@.k)] | Key exists | $..book[?(@.isbn)].title |
&& and || | Combine conditions | $.store.book[?(@.price < 10 && @.inStock == true)].title |
Results on the sample bookstore
| Expression | Returns | Count |
|---|---|---|
$.store.book[*].author | all authors | 4 |
$.store.book[?(@.price < 10)].title | titles of books under 10 | 3 |
$..price | every price, at any depth | 5 |
$.store.book[0,2].title | first and third title | 2 |
Good to know
- Implementations differ in edge cases; RFC 9535 standardised JSONPath in 2024, but many libraries predate it. Plain [-1] is not supported by every implementation, use the slice [-1:].
- A filter on a missing key does not match instead of raising an error.
- kubectl accepts JSONPath templates and the AWS CLI uses JMESPath, a different language, so check the dialect of the tool you use.
Try JSONPath expressions · All cheat sheets · JSON examples