JSONPath
Path:Run a path expression to see results here.
How it works
JSONPath is a query language for JSON, similar to XPath for XML. It lets you extract values from a JSON document using path expressions like $.store.books[*].title. JSONPath is built into Kubernetes, OpenAPI, AWS Step Functions, and many REST API clients.
Paste JSON into the left panel, enter a JSONPath expression starting with $, and click Run. The matched values appear on the right. Toggle Paths to also see the exact path of each match. Use the sample menu to explore common patterns.
JSONPath Quick Reference
| Expression | What it does | Example result |
|---|---|---|
| $ | Root element | Entire document |
| $.store | Child field | Value of store |
| $.store.books[*] | All array elements | Every book object |
| $.store.books[0] | First element (zero-based) | First book |
| $.store.books[-1] | Last element | Last book |
| $.store.books[0:2] | Slice (first two) | Books 0 and 1 |
| $.store.books[0,2] | Multiple indices | Books 0 and 2 |
| $..price | Recursive descent — all price fields | Every price anywhere |
| $.store.* | All children of store | books array + location |
| [?(@.price < 12)] | Filter — price under 12 | Matching items |
| [?(@.active == true)] | Filter — boolean field | Active items |
| [?(@.name =~ /Alice/i)] | Filter — regex match | Items matching regex |
| [?(@.tags)] | Filter — field exists | Items with tags field |
JSONPath vs jq
| Feature | JSONPath | jq |
|---|---|---|
| Root | $ | . |
| All items | $.users[*] | .users[] |
| Filter | [?(@.active)] | select(.active) |
| All names | $.users[*].name | [.users[].name] |
| Recursive | $..price | .. | .price? |
| Transform / reshape | No | Yes |
| Used in | Kubernetes, OpenAPI, Postman | CLI, shell scripts |
Tips & Tricks
Start with $ always
Every valid JSONPath expression starts with $. If your expression returns nothing, check that it starts with the root operator.
.. finds deeply nested values
$..price finds every price field at any depth — useful when you don't know the exact structure.
Toggle Paths to debug
Click Paths in the toolbar to see the exact path string for each match — helpful for verifying that the right nodes are being selected.
@ is the current node
In filter expressions, @ refers to the current element: [?(@.price < 10)] checks each item's price.
Bracket and dot notation mix
$.store['books'][0] is equivalent to $.store.books[0]. Bracket notation is required when a key contains spaces or special characters.
Regex filters (jsonpath-plus)
[?(@.name =~ /^A/i)] selects items whose name starts with A (case-insensitive). This is a jsonpath-plus extension, not in all implementations.
Code Examples
Node.js (jsonpath-plus)
import { JSONPath } from 'jsonpath-plus';
const data = {
store: { books: [{ title: '1984', price: 10.99 }, { title: 'Gatsby', price: 12.99 }] }
};
// All titles
const titles = JSONPath({ path: '$.store.books[*].title', json: data });
console.log(titles); // ['1984', 'Gatsby']
// Books under $12
const cheap = JSONPath({ path: '$.store.books[?(@.price < 12)]', json: data });
console.log(cheap); // [{ title: '1984', price: 10.99 }] Python (jsonpath-ng)
import jsonpath_ng
from jsonpath_ng import parse
data = { "store": { "books": [{"title": "1984", "price": 10.99}] } }
expr = parse("$.store.books[*].title")
matches = [m.value for m in expr.find(data)]
print(matches) # ['1984'] Java (Jayway JSONPath)
// Jayway JSONPath (Java/Spring)
import com.jayway.jsonpath.JsonPath;
String json = "{ \"store\": { \"books\": [{...}] } }";
// Extract all titles
List<String> titles = JsonPath.read(json, "$.store.books[*].title");
// Filter by price
List<Object> cheap = JsonPath.read(json, "$.store.books[?(@.price < 12)]"); Frequently Asked Questions
- What is JSONPath?
- JSONPath is a query language for JSON, similar to XPath for XML. It lets you extract values from a JSON document using path expressions like
$.store.books[*].title. JSONPath was originally defined by Stefan Goessner in 2007 and is now used widely in Kubernetes, OpenAPI, AWS Step Functions, and many REST API clients. - What does $ mean in JSONPath?
- The dollar sign (
$) is the root element — it refers to the top-level object or array of the JSON document. Every JSONPath expression starts with$. For example,$.usersrefers to the users field of the root object. - What is the difference between . and .. in JSONPath?
- A single dot (
.) is the child operator. Double dot (..) is the recursive descent operator —$..pricefinds every price field anywhere in the document, no matter how deeply nested. - How do I filter items with JSONPath?
- Use a filter expression:
[?(@.price < 12)]selects items where price is less than 12. The@refers to the current element. Other examples:[?(@.active == true)],[?(@.name =~ /Alice/i)],[?(@.tags)]. - What is the difference between JSONPath and jq?
- JSONPath uses
$as root and is read-only (extract only). It is built into Kubernetes, OpenAPI, and Postman. jq is a full transformation language that can filter, reshape, sort, and compute values — it uses.as root and runs as a CLI tool. Use JSONPath when your platform supports it; use jq for shell scripts and complex transformations. - How do I select a specific array element?
$.books[0]selects the first element (zero-based).$.books[-1]selects the last.$.books[0:3]selects the first three.$.books[0,2]selects the first and third.- Where is JSONPath used in practice?
- JSONPath is used in Kubernetes (
kubectl get pods -o jsonpath='{.items[*].metadata.name}'), OpenAPI 3.x, AWS Step Functions, Postman test assertions, and Spring Boot's@JsonPathannotation. - Is my data sent to a server?
- No. All JSONPath evaluation runs entirely in your browser using the jsonpath-plus JavaScript library. Your JSON data never leaves your machine and no account or installation is required.
- What JSONPath library does this tool use?
- This tool uses jsonpath-plus v10, which extends the original Goessner spec with regex filter support, type operators, and script expressions. It is compatible with Node.js and browsers.
- How do I use JSONPath in kubectl?
- Pass a JSONPath expression with
-o jsonpath:kubectl get pods -o jsonpath='{.items[*].metadata.name}'. Note that kubectl supports a subset of JSONPath — filter expressions like[?(@.status == 'Running')]are not supported.
Related Tools
Other free developer tools available on DevFormatter.
jq Playground
Run jq queries against JSON data. Full jq 1.6 syntax with transform and reshape support.
JSON Formatter
Format, validate, minify, and sort JSON. Detects duplicate keys and converts to YAML.
YAML Formatter
Format, validate, and convert YAML. Detects YAML 1.1 coercion risks and expands anchors.
XML Formatter
Format, validate, and convert XML. Checks well-formedness with exact error positions.