JSONPath syntax cheat sheet
JSONPath addresses values inside a JSON document the way file paths address files: $.store.book[0].title reads the title of the first book. This cheat sheet covers the syntax you will use daily, with runnable examples.
JSONPath addresses values inside a JSON document the way file paths address files: $.store.book[0].title reads the title of the first book. This cheat sheet covers the syntax you will use daily, with runnable examples.
Every expression starts at the root $, then walks down with dots for object keys and brackets for array indices. That covers most real usage; wildcards, slices, and filters handle the rest.
{
"store": {
"book": [
{ "title": "A", "price": 8.95 },
{ "title": "B", "price": 12.99 }
],
"open": true
}
}| Expression | Selects | Result |
|---|---|---|
| $ | The root | Whole document |
| $.store.open | Object key | true |
| $.store.book[0] | First array item | { title: A, … } |
| $.store.book[0].title | Nested key | "A" |
| $.store.book[-1].title | Last array item | "B" |
| $.store.book[*].title | Wildcard: all titles | ["A", "B"] |
| $..price | Recursive descent | [8.95, 12.99] |
| $.store.book[0:2].title | Slice of items | ["A", "B"] |
Filters select array items by condition. $.store.book[?(@.price < 10)].title returns "A" only. The @ symbol means the current item, and most implementations support comparison and existence checks.
$.store.book[?(@.price < 10)].title // "A"
$.store.book[?(@.title)].price // [8.95, 12.99]Dot notation only suits simple keys. For keys with dots, spaces, or dashes, use bracket quotes: $['weird.key'] or $["kebab-key"]. When a path misbehaves, the key spelling is the first suspect.
The root of the document. Every JSONPath expression starts at $ and walks down, so $.store.book[0] means: from the root, key store, key book, index 0.
Use the wildcard: $.store.book[*].title returns every title. For a range, use a slice like [0:2]. For matching items, use a filter like [?(@.price < 10)].
Usual causes: a misspelled key, 1-based indexing instead of 0-based, or addressing an object where the document has an array. Paste the document into the path finder to browse the real paths.