JSONPath
Path:Run a path expression to see results here.
JSONPath is a query language for extracting values from JSON documents, similar to XPath for XML. Defined by Stefan Goessner in 2007, it uses expressions like $.store.books[*].title to navigate JSON structures. JSONPath is built into Kubernetes kubectl, OpenAPI 3.x specifications, AWS Step Functions, and many REST API testing tools.
JSONPath Playground
How it works
Last updated: November 2026 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. The dollar sign$represents the root of the document. The dot.is the child operator, and*is a wildcard. Square brackets are used for array indexing, slicing, and filter expressions. Unlike jq, JSONPath is a read-only query language — it extracts values but cannot transform, sort, or reshape the data. The jsonpath-plus library used in this playground extends the original Goessner spec with regex matching and additional operators, making it one of the most capable JSONPath implementations available in JavaScript. - 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, and$.users[0].namereaches the name field of the first user. If the JSON root is an array rather than an object,$[*]iterates all items and$[0]accesses the first. In Kubernetes kubectl, the equivalent is{.items[*].metadata.name}— kubectl uses{}wrapper syntax instead of$. In filter expressions,$can also appear as a back-reference to the root inside a nested filter, while@refers to the current node being evaluated. - What is the difference between . and .. in JSONPath?
- A single dot (
.) is the child operator —$.store.booksaccesses the books field inside the store object. Double dot (..) is the recursive descent operator —$..pricefinds every price field anywhere in the document, no matter how deeply nested. This is the JSONPath equivalent of XPath's//axis. Recursive descent is particularly useful when querying deeply nested or variable-structure JSON such as API responses with unknown nesting. For example,$..namewill find every name field at any depth in the document, including in nested arrays and objects. It can produce many results on large documents, so combine it with a more specific suffix like$..books[*].titleto narrow the scope and avoid unexpected matches from unrelated parts of the JSON tree. - How do I filter items with JSONPath?
- Use a filter expression inside square brackets:
[?(@.price < 12)]selects all items where the price field is less than 12. The@symbol refers to the current element being evaluated. Additional examples:[?(@.active == true)]selects active items,[?(@.name =~ /Alice/i)]matches by regex (a jsonpath-plus extension), and[?(@.tags)]selects items that have a tags field. Comparison operators supported are==,!=,<,<=,>, and>=. Logical operators&&and||combine multiple conditions:[?(@.price < 20 && @.inStock == true)]. Note that filter support varies across JSONPath implementations — not all support regex or logical operators. - What is the difference between JSONPath and jq?
- JSONPath uses
$as root and is read-only — it extracts values but cannot transform, sort, or reshape them. It is built into Kubernetes, OpenAPI 3.x, AWS Step Functions, and Postman, making it the right choice when your platform already supports it natively. jq is a full transformation language that can filter, reshape, sort, reduce, and compute new values from JSON. jq uses.as root and runs as a command-line tool or via libraries like jq-web in Node.js. For simple field extraction from API responses in a Kubernetes or Postman context, use JSONPath. For complex shell scripting, CI/CD pipelines, or any task requiring data reshaping, sorting, or arithmetic, use jq. The jq Playground on this site supports the full jq 1.6 syntax and runs in the browser. - How do I select a specific array element?
- Use square bracket notation with a zero-based index:
$.books[0]selects the first book.$.books[-1]selects the last element (supported in jsonpath-plus).$.books[0:3]selects the first three elements using Python-style slice notation.$.books[0,2]selects the first and third elements by listing specific indices separated by commas. The wildcard$.books[*]selects all elements in the array — equivalent to iterating every item. Note that negative index support and slice syntax are extensions beyond the original Goessner specification and may not be available in all JSONPath implementations. The jsonpath-plus library used in this playground supports all of these forms, but the Jayway JSONPath library for Java uses different slice semantics, so test your expressions against the specific library your production environment uses. - Where is JSONPath used in practice?
- JSONPath is used across many platforms. In Kubernetes, the
kubectlCLI supports it via-o jsonpath='{.items[*].metadata.name}'. OpenAPI 3.x uses JSONPath to reference schema components. AWS Step Functions uses JSONPath for input/output path filtering in state machine definitions — fields likeInputPath,ResultPath, andOutputPathall accept JSONPath expressions. Postman and Insomnia support it in test assertions to verify API response values. In Java, the Spring Framework's@JsonPathannotation and the Jayway JSONPath library (com.jayway.jsonpath) are the standard implementations. The jsonpath-plus npm package (used in this tool) is a popular JavaScript implementation compatible with both Node.js and browsers, used by thousands of projects including testing frameworks like Jest and Cypress. - 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. The jsonpath-plus library is bundled as a static asset and loaded from the same domain. No external API calls are made when you run a query. This means sensitive JSON data — such as API responses containing tokens, user records, or private configuration — is safe to paste into the tool. The playground also works offline after the page has been loaded once, since all processing is local. Clearing your browser cache will remove any locally stored state; the tool does not persist your input between sessions unless your browser restores tabs automatically.
- What JSONPath library does this tool use?
- This tool uses jsonpath-plus v10, a widely adopted JavaScript implementation that extends the original Goessner 2007 specification with regex filter support (
=~ /pattern/flags), type operators (@.string(),@.number()), and script expressions. It is compatible with Node.js and all modern browsers and is downloaded over two million times per week from npm. The package is available asnpm install jsonpath-plus. Because jsonpath-plus extends the spec, some expressions (particularly regex filters) will not work in Kubernetes kubectl, Jayway JSONPath for Java, or the Python jsonpath-ng library. For cross-platform compatibility, stick to the core features: dot notation, bracket notation, wildcards, recursive descent, array slices, and basic filter expressions with comparison operators. - How do I use JSONPath in kubectl?
- Pass a JSONPath expression to kubectl with
-o jsonpath:kubectl get pods -o jsonpath='{.items[*].metadata.name}'lists all pod names. kubectl uses curly brace wrappers instead of a leading$. Use-o jsonpath-fileto load a longer expression from a file. kubectl supports a subset of JSONPath — it supports basic path traversal, wildcards, and array indices, but does not support filter expressions like[?(@.status.phase == 'Running')]. For filtering in kubectl, use--field-selectoror pipe output tojq. The range iterator syntax{range .items[*]}{.metadata.name} {end}outputs each name on its own line, which is useful for shell scripting. Use\nbetween fields to control output formatting.
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.
JSON Diff
Compare two JSON objects side-by-side. See added, removed, and changed keys with full paths.