JSONPath Cheat Sheet
Every JSONPath operator, filter expression, and selector in one place. Includes a sample document, 15+ practical examples with results, and jq equivalents.
JSONTech TeamMarch 10, 20256 min read
Sample JSON Document
All examples below use this bookstore dataset:
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 399.99
}
}
}Core Operators
| Operator | Description | Example | Result |
|---|---|---|---|
$ | Root object | $ | The entire document |
. | Child operator (dot notation) | $.store.bicycle.color | "red" |
.. | Recursive descent (deep scan) | $..price | [8.95, 12.99, 8.99, 22.99, 399.99] |
* | Wildcard — all children | $.store.book[*].author | All 4 author names |
[] | Bracket notation / subscript | $.store.book[0] | First book object |
[,] | Union — multiple indices | $.store.book[0,2] | 1st and 3rd books |
[start:end] | Array slice | $.store.book[0:2] | First 2 books (index 0, 1) |
[start:end:step] | Array slice with step | $.store.book[::2] | Every other book (index 0, 2) |
[?()] | Filter expression | $.store.book[?(@.price < 10)] | Books cheaper than $10 |
@ | Current node (used in filters) | @.price | Price of current element |
.length | Length of array or string | $.store.book.length | 4 |
Filter Operators
Used inside [?()] filter expressions with @ referencing the current node:
| Operator | Meaning | Example |
|---|---|---|
== | Equals | [?(@.category == "fiction")] |
!= | Not equals | [?(@.category != "reference")] |
< | Less than | [?(@.price < 10)] |
> | Greater than | [?(@.price > 20)] |
<= | Less than or equal | [?(@.price <= 8.99)] |
>= | Greater than or equal | [?(@.price >= 12.99)] |
=~ | Regex match | [?(@.author =~ /.*Tolkien/i)] |
in | Value in list | [?(@.category in ["fiction", "reference"])] |
nin | Value not in list | [?(@.category nin ["reference"])] |
&& | Logical AND | [?(@.price < 10 && @.category == "fiction")] |
|| | Logical OR | [?(@.price < 10 || @.price > 20)] |
Practical Examples
| Expression | Description | Result |
|---|---|---|
$.store.book[*].author | All authors | ["Nigel Rees", "Evelyn Waugh", "Herman Melville", "J. R. R. Tolkien"] |
$..author | All authors (recursive) | Same as above |
$.store.* | All things in the store | Book array + bicycle object |
$..price | All prices everywhere | [8.95, 12.99, 8.99, 22.99, 399.99] |
$.store.book[2] | Third book (zero-indexed) | Moby Dick object |
$.store.book[-1] | Last book | The Lord of the Rings object |
$.store.book[0:2] | First two books | Sayings of the Century, Sword of Honour |
$.store.book[?(@.isbn)] | Books that have an ISBN | Moby Dick, The Lord of the Rings |
$.store.book[?(!@.isbn)] | Books without an ISBN | Sayings of the Century, Sword of Honour |
$.store.book[?(@.price < 10)] | Books cheaper than $10 | Sayings of the Century, Moby Dick |
$.store.book[?(@.price > 20)] | Books over $20 | The Lord of the Rings |
$.store.book[?(@.category == "fiction")] | Fiction books only | Sword of Honour, Moby Dick, The Lord of the Rings |
$.store.book[?(@.author =~ /.*Melville/)] | Author matching regex | Moby Dick |
$..book[?(@.price < 10 && @.isbn)] | Cheap books with ISBN | Moby Dick |
$.store.book[*].title | All book titles | ["Sayings of the Century", "Sword of Honour", "Moby Dick", "The Lord of the Rings"] |
$.store.book.length | Number of books | 4 |
JSONPath vs jq
| Task | JSONPath | jq Equivalent |
|---|---|---|
| Root | $ | . |
| Child access | $.store.book | .store.book |
| Array index | $.store.book[0] | .store.book[0] |
| All elements | $.store.book[*] | .store.book[] |
| Recursive | $..price | .. | .price? // empty |
| Filter by value | $.store.book[?(@.price < 10)] | .store.book[] | select(.price < 10) |
| Field existence | $.store.book[?(@.isbn)] | .store.book[] | select(has("isbn")) |
| Slice | $.store.book[0:2] | .store.book[:2] |
| Multiple fields | $..book[*]['title','price'] | .store.book[] | {title, price} |
Common Mistakes
| Mistake | Problem | Fix |
|---|---|---|
store.book[0] | Missing root $ | $.store.book[0] |
$.store.book[?(@.price = 10)] | Single = (assignment) instead of == | $.store.book[?(@.price == 10)] |
$.store.book[1:3:0] | Step of 0 is invalid | $.store.book[1:3] or [1:3:1] |
$..book..author | Double recursive can produce duplicates | $..book[*].author or $..author |
| Unquoted string in filter | [?(@.cat == fiction)] fails | [?(@.cat == "fiction")] |
Forgetting @ in filters | [?(price < 10)] fails | [?(@.price < 10)] |
Test your JSONPath expressions live: Paste your JSON and try any expression in our JSONPath Tester — see matching results instantly.