JSONPath Cheat Sheet: Syntax and Examples
Last updated:
JSONPath is a query language for JSON analogous to XPath for XML — it extracts values using path expressions without parsing the entire document in application code. RFC 9535 (2024) is the current standard; the Stefan Goessner spec (2007) was the de facto standard for 17 years and differs in recursive descent and filter syntax. The 4 core operators are $ (root), . (child), [*] (all array items), and ?(...) (filter expression). Array slices follow Python notation: [0:3] returns elements 0, 1, 2; [-1] returns the last element. This cheatsheet covers all operators, filter expressions with comparison operators, wildcards, array slices, recursive descent (..), the @ current node reference, and key differences between JSONPath and jq.
Test JSONPath expressions online
Paste your JSON and a JSONPath expression to see the extracted values instantly — no install needed.
Open JSONPath TesterSample JSON used in examples
{
"store": {
"name": "Books & More",
"books": [
{ "title": "Clean Code", "author": "Robert Martin", "price": 35.99, "inStock": true },
{ "title": "The Pragmatic Programmer", "author": "Hunt & Thomas", "price": 45.00, "inStock": true },
{ "title": "Design Patterns", "author": "Gang of Four", "price": 54.95, "inStock": false },
{ "title": "Refactoring", "author": "Martin Fowler", "price": 42.50, "inStock": true }
],
"location": { "city": "San Francisco", "zip": "94105" }
}
}Syntax quick reference
| Syntax | Meaning |
|---|---|
$ | Root element |
.key | Child key (dot notation) |
['key'] | Child key (bracket notation) |
.. | Recursive descent — search all levels |
[*] | Wildcard — all elements of an array |
[0] | Array index (zero-based) |
[-1] | Last element |
[0,2] | Multiple indexes |
[0:3] | Slice — elements 0, 1, 2 |
[?(@.key)] | Filter — elements where key exists |
[?(@.key == val)] | Filter — elements where key equals val |
[?(@.key > val)] | Filter — elements where key > val |
Examples
Basic property access
$.store.name
→ "Books & More"
$.store.location.city
→ "San Francisco"
$.store.location['zip']
→ "94105"Array access
$.store.books[0].title
→ "Clean Code"
$.store.books[-1].title
→ "Refactoring"
$.store.books[1].price
→ 45.00Wildcard — all elements
$.store.books[*].title
→ ["Clean Code", "The Pragmatic Programmer", "Design Patterns", "Refactoring"]
$.store.books[*].price
→ [35.99, 45.00, 54.95, 42.50]Array slices
$.store.books[0:2].title
→ ["Clean Code", "The Pragmatic Programmer"]
$.store.books[2:].title
→ ["Design Patterns", "Refactoring"]Multiple indexes
$.store.books[0,3].title
→ ["Clean Code", "Refactoring"]Recursive descent
$..title
→ ["Clean Code", "The Pragmatic Programmer", "Design Patterns", "Refactoring"]
$..price
→ [35.99, 45.00, 54.95, 42.50]Filter expressions
// Books that are in stock
$.store.books[?(@.inStock == true)].title
→ ["Clean Code", "The Pragmatic Programmer", "Refactoring"]
// Books cheaper than $40
$.store.books[?(@.price < 40)].title
→ ["Clean Code"]
// Books $40 or more
$.store.books[?(@.price >= 40)].title
→ ["The Pragmatic Programmer", "Design Patterns", "Refactoring"]Combining conditions
// In-stock books under $50
$.store.books[?(@.inStock == true && @.price < 50)].title
→ ["Clean Code", "The Pragmatic Programmer", "Refactoring"]Implementation differences
JSONPath was originally described by Stefan Goessner in 2007 with no formal standard. Different libraries implement it differently. Common variation points:
- Negative indexes —
[-1]works in most implementations but not all. - Regex filters —
=~operator is not universally supported. - RFC 9535 — A formal JSONPath standard was published in 2024. New libraries may behave differently from older ones.
JSONPath vs jq
jq is a command-line JSON processor with its own more powerful query language. Use JSONPath when embedding queries in application code or config files. Use jq for shell scripting and one-off transformations in the terminal.
Test JSONPath expressions live
Paste any JSON and write JSONPath expressions in Jsonic's JSONPath Tester. Results update as you type. Nothing is uploaded.
Open JSONPath TesterFrequently asked questions
What is JSONPath?
JSONPath is a query language for extracting values from JSON data, analogous to XPath for XML. It uses path expressions starting with $ (root), dots for child navigation, and brackets for array access. Widely used in APIs, test frameworks, and data processing tools.
What is the difference between $ and @ in JSONPath?
$ refers to the root of the JSON document — every expression starts with it. @ refers to the current node inside filter expressions like [?(@.price < 40)]. Outside filters, only $ is used.
How do I filter an array with JSONPath?
Use [?(@.key operator value)]. Example: $.books[?(@.price < 30)] selects books cheaper than $30. Combine conditions with && or ||. Regex matching with =~ is not universally supported across implementations.
What is the JSONPath wildcard selector?
* selects all elements at one level: $.books[*].title gets titles of all books. It differs from .. (recursive descent), which searches all nesting levels rather than just one.
What is the difference between dot notation and bracket notation?
Both navigate to the same key: $.store.name equals $.store["name"]. Bracket notation is required for keys with spaces or special characters. Array elements always use bracket notation: $.books[0].
How do I get all values of a key at any depth?
Use recursive descent: $..title selects all title values anywhere in the document regardless of nesting depth. Combine with filters: $..books[?(@.price > 30)] finds all books at any depth where price exceeds $30.
Recommended reading
- Designing Data-Intensive Applications (2nd Edition) — Martin Kleppmann & Chris RiccominiThe modern classic on data systems — encoding formats, schemas, replication, and stream processing.
- JavaScript: The Definitive Guide (7th Edition) — David FlanaganThe complete reference for the language JSON came from — serialization, async, and the full standard library.
As an Amazon Associate, Jsonic earns from qualifying purchases.