JSONPath is a query language for picking values out of a JSON document, the way XPath does for XML. It's used in API testing tools, Kubernetes (kubectl -o jsonpath), databases and many libraries, and since 2024 it's standardised as RFC 9535. Every example below uses this document and was checked in the JSON Query Selector, where you can paste it and try them yourself.
{
"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 }
}
}Basic selectors
| Expression | Meaning | Result |
|---|---|---|
| $ | The root of the document | the whole document |
| $.store.bicycle.color | A child by name (dot notation) | "red" |
| $['store']['bicycle'] | A child by name (bracket notation, for keys with spaces or symbols) | { "color": "red", "price": 399 } |
| $.store.* | Wildcard: every child | the book array and the bicycle object |
| $..author | Recursive descent: author at any depth | "Nigel Rees", "Evelyn Waugh", "Herman Melville", "J. R. R. Tolkien" |
| $..price | Every price anywhere | 8.95, 12.99, 8.99, 22.99, 399 |
Arrays: indexes and slices
| Expression | Meaning | Result |
|---|---|---|
| $.store.book[0].title | The first item (indexes start at 0) | "Sayings of the Century" |
| $.store.book[-1].title | The last item | "The Lord of the Rings" |
| $.store.book[0,2].title | Several indexes | "Sayings of the Century", "Moby Dick" |
| $.store.book[0:2].title | A slice: from index 0 up to (not including) 2 | "Sayings of the Century", "Sword of Honour" |
| $.store.book[*].author | Every item | all four authors |
Filters
| Expression | Meaning | Result |
|---|---|---|
| $.store.book[?@.price < 10].title | Items where a comparison is true (@ is the current item) | "Sayings of the Century", "Moby Dick" |
| $.store.book[?@.isbn].title | Items that have a key | "Moby Dick", "The Lord of the Rings" |
| $.store.book[?@.category == 'fiction' && @.price > 10].title | Combine conditions with && and || | "Sword of Honour", "The Lord of the Rings" |
| $..book[?length(@.title) > 15].title | length() of a string, array or object | "Sayings of the Century", "The Lord of the Rings" |
| $.store.book[?count(@.*) > 4].title | count(): the number of matches of a query (here, keys per book) | "Moby Dick", "The Lord of the Rings" |
| $.store.book[?value(@.price) > 20].title | value(): the single value a query matches | "The Lord of the Rings" |
| $.store.book[?match(@.author, '.*Tolkien')].title | match(): the whole value matches a regular expression | "The Lord of the Rings" |
| $.store.book[?search(@.author, 'Mel')].title | search(): the value contains a match | "Moby Dick" |
Filter operators
- Comparison:
==!=<<=>>= - Logic:
&&(and),||(or),!(not), and parentheses for grouping - Strings use single or double quotes:
@.category == 'fiction' $inside a filter refers to the document root, so values can be compared with other parts of the document- Functions from RFC 9535:
length(),count(),match(),search()andvalue()
Tips
- A query always returns a list of matches, even when only one value matches, and an empty list when none do.
- Use bracket notation for keys that aren't simple names:
$['first name'],$['user-id']. - Don't know the path to a value? Search for it with JSON Deep Search, which shows the full path of every match, or click it in the Tree Viewer.