JSONPath is a query language for picking values out of a JSON document — like XPath for JSON. Here's the syntax with worked examples. Run any of them live in the JSONPath tester.
Open the JSONPath tester →The examples below run against this JSON:
{
"store": {
"book": [
{ "title": "Sayings of the Century", "price": 8.95 },
{ "title": "Moby Dick", "price": 12.99 },
{ "title": "The Lord of the Rings", "price": 22.99 }
],
"bicycle": { "color": "red", "price": 19.95 }
}
}
| Syntax | Meaning |
|---|---|
$ | The root object |
.key or ['key'] | Child by name |
..key | Recursive descent — find key at any depth |
* | Wildcard — all children |
[n] | Array element by index (0-based) |
[start:end] | Array slice (end exclusive) |
[?(@.x > 1)] | Filter — elements where the expression is true (@ = current item) |
[a,b] | Union — multiple names or indices |
| JSONPath | Selects |
|---|---|
$.store.book[*].title | All three book titles |
$..price | Every price: 8.95, 12.99, 22.99, 19.95 |
$.store.book[0] | The first book object |
$.store.book[-1].title | "The Lord of the Rings" (last book) |
$.store.book[0:2] | The first two books |
$.store.book[?(@.price < 10)] | Books cheaper than 10 (the first book) |
$..book[?(@.price > 20)].title | Titles of books over 20 |
$.store.* | Everything in the store (the book array and the bicycle) |
$..* | Every value in the document, recursively |
Note: a few details (e.g. negative indices, the exact filter grammar) vary between JSONPath implementations. Paste your document into the tester to confirm what a given expression returns for your data.
Try these in the JSONPath tester →