Guide
JSONPath Explained with Examples
JSONPath is a small query language for pointing at values inside a JSON document, the way XPath does for XML. It is handy for pulling a field out of a large response, writing assertions in tests, and configuring tools that extract data. This guide teaches it by example.
The document we will query
Every example below runs against this JSON:
{
"store": {
"books": [
{ "title": "Dune", "price": 12, "inStock": true },
{ "title": "Neuromancer", "price": 9, "inStock": false },
{ "title": "Snow Crash", "price": 15, "inStock": true }
],
"owner": { "name": "Ada", "city": "Berlin" }
}
}The basics: root, dots, and brackets
A JSONPath expression starts at the root, written as $. From there you walk down into the data with dot notation for keys and square brackets for array indexes.
- $ is the whole document.
- $.store.owner.name selects "Ada".
- $.store.books[0].title selects "Dune", since arrays are zero-indexed.
- $.store.books[-1].title selects "Snow Crash" using a negative index from the end.
Bracket notation also works for keys, so $.store.owner.name and $['store']['owner']['name'] mean the same thing. Brackets are useful when a key has spaces or characters that dot notation cannot express.
Wildcards select many values
The wildcard * matches every element or every property at a level, turning a single selection into a list.
- $.store.books[*].title selects every title: "Dune", "Neuromancer", "Snow Crash".
- $.store.books[*] selects every book object.
- $.store.* selects every value directly under store, which here is the books array and the owner object.
Recursive descent finds fields anywhere
The .. operator searches at any depth, so you do not have to know the exact path. It is the tool for grabbing a field wherever it lives.
- $..title selects every title anywhere in the document.
- $..price selects every price, no matter how deeply nested.
Recursive descent is powerful and a little blunt. It will match a key wherever it appears, so use it when you genuinely want every occurrence.
Filters select by condition
Filter expressions, written as [?(...)], keep only the items that match a condition. Inside the filter, @ refers to the current item.
- $.store.books[?(@.inStock == true)] selects the books that are in stock.
- $.store.books[?(@.price < 10)] selects books cheaper than 10, which is Neuromancer.
- $.store.books[?(@.price < 13)].title selects the titles of books under 13: "Dune" and "Neuromancer".
Filters are where JSONPath goes from addressing a known location to querying data by its values, which is what makes it useful against responses you have not seen before.
Trying it on real data
The fastest way to learn JSONPath is to run expressions against a document and watch what they select. In the visualizer you can search a payload and copy the path to any node, which gives you a correct expression to build from. In the editor, JSONPath context shows the path of whatever value your cursor is on, so you can see how a location maps to an expression.
JSONPath has small dialect differences between implementations, especially around filters and the exact output shape. When you use it in a specific tool or library, check that tool's notes for its exact syntax.
FAQ
What does the $ mean in JSONPath?
It is the root of the document. Every JSONPath expression starts at $ and walks down into the data from there.
What is the difference between . and .. ?
A single dot moves one level down to a named key. Two dots are recursive descent, which searches for a key at any depth in the document.
Does every tool support the same JSONPath syntax?
Mostly, but not exactly. The basics are consistent across implementations, while filter syntax and the exact result shape can vary. Check the notes for the specific library or tool you use.