JSONPath is a compact query language for pulling specific values out of a JSON document, the way XPath does for XML. Instead of looping through nested objects in code, you write one expression like $.store.book[*].title and get back exactly the values you want. It is perfect for testing API responses and digging into deep, messy payloads.
JSONPath syntax in one pass
Every expression starts at the root and walks down into the structure. These are the pieces you will use most:
$is the root of the document. Every query begins here..nameselects a child by key, for example$.store...is recursive descent: it searches every level below the current point for a match.$..pricefinds everypriceanywhere in the document, no matter how deep.[0]selects an array element by index.['key']is bracket notation for a child, useful when a key has spaces or dots.*is the wildcard: it matches all elements of an array or all values of an object.$.store.book[*]is every book.[start:end]is an array slice, end-exclusive, like Python.[0:2]returns the first two items.[?(@.price < 10)]is a filter expression.@refers to the current element, so this keeps only items whosepriceis under 10.
Worked examples
Here is a small sample to query against:
{
"store": {
"book": [
{ "title": "JSON Basics", "price": 8, "active": true },
{ "title": "Advanced APIs", "price": 24, "active": false },
{ "title": "Query Languages", "price": 6, "active": true }
]
},
"items": [
{ "id": 1, "active": true },
{ "id": 2, "active": false }
]
}
Get every book title with a wildcard:
$.store.book[*].title
Returns ["JSON Basics", "Advanced APIs", "Query Languages"].
Find every price in the whole document with recursive descent:
$..price
Returns [8, 24, 6]. Notice you never named store or book. The .. walks the entire tree for you.
Keep only active items with a filter:
$.items[?(@.active==true)]
Returns the object with id: 1. Swap in $.store.book[?(@.price < 10)].title to get the titles of the cheap books, which gives ["JSON Basics", "Query Languages"].
Test JSONPath in your browser
The fastest way to learn the syntax is to run expressions against your own data and watch the matches highlight.
- Open the JSONPath Tester and paste your JSON into the input.
- Type an expression in the query box, starting with
$. - Read the matched values in the results panel.
- Tweak the path, add a
*wildcard or a[?()]filter, and rerun until it returns exactly what you need.
Everything runs client-side, so your JSON never leaves your device. Paste a real API response, confirm the path you plan to use in code, and you will catch mistakes before they ship. When an expression returns nothing, the JSONPath Tester makes it obvious so you can adjust the key or filter.
Related tools
- Messy JSON that is hard to read? Clean it up with the JSON Formatter.
- Need to document a payload’s shape? Try the JSON Schema Generator.
- Turning extracted records into a spreadsheet? Use JSON to CSV.
Write the path once, test it live, and stop hand-rolling loops just to read one value.