JSON Path is a query language for JSON, similar to XPath for XML. It allows you to navigate complex JSON structures and extract specific values without writing custom parsing code.
JSON Path Syntax
The root element is always referred to as $. From there, you use dot notation or bracket notation to navigate deeper.
Basic Operators
| Operator | Description | Example |
|---|---|---|
$ | Root object | $ |
. | Child member | $.store |
.. | Recursive descent | $..price |
[] | Array index or child | $.items[0] |
[] | Wildcard (all elements) | $.items[] |
[start:end] | Array slice | $.items[0:3] |
[?()] | Filter expression | $..book[?(@.price<10)] |
Practical Examples
Given this JSON:
{
"store": {
"books": [
{"title": "Book A", "price": 8.95},
{"title": "Book B", "price": 12.99}
]
}
}
| Path | Result |
|---|---|
$.store.books[0].title | "Book A" |
$.store.books[*].price | [8.95, 12.99] |
$..title | ["Book A", "Book B"] |
$.store.books[?(@.price<10)] | [{"title": "Book A", ...}] |
Common Use Cases
JSON Path vs JavaScript Access
| Task | JavaScript | JSON Path |
|---|---|---|
| First book title | data.store.books[0].title | $.store.books[0].title |
| All prices | data.store.books.map(b => b.price) | $..price |
| Filtered results | data.store.books.filter(b => b.price < 10) | $.store.books[?(@.price<10)] |
Try It Yourself
Explore and query JSON data with our free JSON Path Finder. Paste your JSON, write a path expression, and see results instantly.