JSONPath Query Language
A complete reference for using JSONPath expressions in the JSON Formatter tool.
What is JSONPath?
JSONPath is a query language for JSON data, similar to how XPath works for XML. It lets you navigate into a JSON structure and extract specific values using a concise expression syntax.
In the JSON Formatter, type a JSONPath expression into the JSONPath input field. Matching results appear above the tree, and matched nodes are highlighted in blue.
Syntax Reference
| Expression | Description | Example |
|---|---|---|
| $ | The root object | $ |
| .key | Child property access | $.store.name |
| ['key'] | Bracket notation (for special characters in keys) | $['first-name'] |
| [n] | Array index (0-based, negative supported) | $.items[0] |
| [*] | Wildcard — all items in an array or all values in an object | $.items[*].name |
| .* | Wildcard (dot notation) | $.store.* |
| .. | Recursive descent — searches all levels | $..name |
| [start:end] | Array slice (start inclusive, end exclusive) | $.items[0:3] |
| [?()] | Filter expression | $.items[?(@.price < 10)] |
| .length | Array or object length | $.items.length |
Examples
Given this sample JSON:
{
"store": {
"books": [
{ "title": "The Great Gatsby", "author": "Fitzgerald", "price": 10.99, "year": 1925 },
{ "title": "To Kill a Mockingbird", "author": "Lee", "price": 8.99, "year": 1960 },
{ "title": "1984", "author": "Orwell", "price": 7.99, "year": 1949 },
{ "title": "Pride and Prejudice", "author": "Austen", "price": 6.99, "year": 1813 }
],
"location": { "city": "New York", "country": "US" }
}
}
Basic Property Access
| Query | Result |
|---|---|
| $.store.location.city | "New York" |
| $.store.books[0].title | "The Great Gatsby" |
| $.store.books[-1].title | "Pride and Prejudice" (last item) |
Wildcards
| Query | Result |
|---|---|
| $.store.books[*].title | ["The Great Gatsby", "To Kill a Mockingbird", "1984", "Pride and Prejudice"] |
| $.store.* | All direct children of store (the books array and location object) |
Recursive Descent
The .. operator searches through all nested levels:
| Query | Result |
|---|---|
| $..author | ["Fitzgerald", "Lee", "Orwell", "Austen"] |
| $..price | [10.99, 8.99, 7.99, 6.99] |
Array Slicing
Slice syntax is [start:end] where start is inclusive and end is exclusive. Negative indices count from the end.
| Query | Result |
|---|---|
| $.store.books[0:2] | First two books (index 0 and 1) |
| $.store.books[-2:] | Last two books |
| $.store.books[::2] | Every other book (step of 2) |
Filter Expressions
Filter expressions use [?()] syntax with @ referring to the current element. You can use comparison operators (==, !=, <, >, <=, >=) and logical operators (&&, ||).
| Query | Result |
|---|---|
| $.store.books[?(@.price < 9)] | Books cheaper than $9 (Lee, Orwell, Austen) |
| $.store.books[?(@.year > 1900)] | Books published after 1900 (Gatsby, Mockingbird, 1984) |
| $.store.books[?(@.price < 9 && @.year > 1900)] | Cheap books from 20th century onward (Lee, Orwell) |
Length
| Query | Result |
|---|---|
| $.store.books.length | 4 |
Combining Expressions
You can chain expressions to drill down into filtered results:
| Query | Result |
|---|---|
| $.store.books[?(@.price < 9)].title | ["To Kill a Mockingbird", "1984", "Pride and Prejudice"] |
| $.store.books[0:2].author | ["Fitzgerald", "Lee"] |
Tips
- All expressions must start with
$(the root). - Hover any node in the tree to see its full path. Click to copy the path.
- Use the Search field for simple text filtering and the JSONPath field for structured queries — they work independently.
- When a JSONPath query is active, matching nodes are highlighted in blue in the tree and their parent nodes are auto-expanded.
- Results appear above the tree with a match count badge. Click Copy to copy the query results as JSON.
- Recursive descent (
..) is useful when you know the key name but not its exact location in the structure. - Filter expressions support any JavaScript comparison —
==,!=,<,>,<=,>=,&&,||.
Ready to try it out?
Open JSON Formatter