JSONPath Tester
Query a JSON document with JSONPath and see what comes back, live. Use it when the value you need is six levels down in an API response and you want the expression right before it goes into code.
1 JSONPath Tester example
Path
$.store.book[?(@.price < 15)].title Result
2
3
4
[
"The Left Hand of Darkness",
"Sapiens"
] 2 Syntax
Selecting
- $: the root
- $.store.name: a child key
- $['odd key']: a key with spaces
- $.book[0]: by index
- $.book[*]: every element
- $..price: at any depth
Narrowing
- $.book[0:2]: a slice
- $.book[-1:]: the last one
- $.book[0,2]: a union
- [?(@.price < 15)]: a filter
- [?(@.author == 'Harari')]: an equality test
- [?(@.tags)]: key exists
3 Two common mistakes
The @ is not optional
Start every field in a filter with @. Inside a filter, @ means the current element, so write [?(@.price < 100)], never [?(price < 100)]. Without it, the filter returns nothing.
JSONPath is not jq
JSONPath selects; it cannot reshape. To rename keys, compute a total or build a new object, use jq instead, because JSONPath has no syntax for any of that.
4 Implementations disagree
JSONPath started as a blog post in 2007 and did not get a formal
specification until RFC 9535 in 2024. In the seventeen years
between, every library made its own decisions about filters,
unions, and what a missing key should do. This page uses
jsonpath-plus, which is permissive; the Jayway implementation
behind most Java tooling and the one built into Kubernetes
kubectl both differ in places.
For a simple path, the differences do not show. For anything
with a filter or a script expression, test against
the implementation you ship. A path that
works here can return a different result in Java or
kubectl.
Steps
Testing JSONPath filters on nested payloads
- 01 Paste a JSON document into the left panel.
- 02 Type a JSONPath expression in the Path field. Results appear as you type, with a match count above.
- 03 Start from $ and walk down: $.store.book[0].title. Use .. to search at any depth, and [?(@.price < 100)] to filter.
- 04 Copy Result puts the matches on the clipboard as a JSON array.
In code
How to query JSON from code and the command line
Command line
bash# jq is the usual tool at a shell, and its syntax is its own
curl -s https://api.example.com/store | jq '.store.book[] | select(.price < 100000) | .title'
# jq can reshape, which JSONPath cannot
jq '{titles: [.store.book[].title], total: ([.store.book[].price] | add)}' store.json
# kubectl speaks JSONPath specifically
kubectl get pods -o jsonpath='{.items[*].metadata.name}'
kubectl get nodes -o jsonpath='{.items[?(@.spec.unschedulable)].metadata.name}' If you are picking one to learn, we recommend jq. Learn JSONPath because kubectl, Kibana and much of the Java tooling use it.
JavaScript / Node.js
js// npm i jsonpath-plus
const { JSONPath } = require("jsonpath-plus");
JSONPath({ path: "$..book[?(@.price < 100000)].title", json: data });
// Get the paths rather than the values, which is handy for building
// an editable form or reporting where something was found
JSONPath({ path: "$..price", json: data, resultType: "path" });
// Both at once
JSONPath({ path: "$..price", json: data, resultType: "all" }); Python
python# pip install jsonpath-ng
from jsonpath_ng.ext import parse # .ext adds filter support
expr = parse("$..book[?price < 100000].title")
print([m.value for m in expr.find(data)])
# Note the syntax difference: jsonpath-ng writes filters without the @
# and without the parentheses that jsonpath-plus requires. Expressions
# are not portable between libraries. Debugging
Dialect differences in filters and recursive descent
- A filter returns nothing
- Check for a missing @. Inside a filter, write [?(@.price < 100)], never [?(price < 100)]. Without the @, the filter matches nothing.
- A string comparison never matches
- Quote the value: [?(@.role == 'admin')]. Without quotes it is read as an identifier, not a string.
- An expression that works elsewhere fails here
- Implementations differ. JSONPath had no specification until RFC 9535 in 2024, so filters, unions and missing-key behavior vary between libraries.
- A key with a dot or space in it cannot be reached
- Use bracket notation with quotes: $['content-type'] or $['my key'].
- The result is wrapped in an array instead of being one value
- JSONPath always returns a list of matches, even when there is exactly one. Take [0] yourself.
Spec notes
RFC 9535 standard JSONPath behavior
JSONPath began as a 2007 blog post by Stefan Goessner, modeled on XPath, and spread through implementations that each filled the gaps differently. RFC 9535 standardized it in 2024. However, the RFC does not change the libraries already in your dependency tree, so test any expression beyond a plain path against the implementation you ship.
RFCs
RFC 9535 JSONPath specification
Answers
JSONPath query questions
What is JSONPath?
A query language for JSON, loosely modeled on XPath. $ is the root, dots walk into keys, brackets index arrays, and .. searches at any depth. Use it when the value you want is six levels down in an API response.
Which expressions are supported?
Child access ($.store.book), wildcards ($.book[*]), recursive descent ($..price), slices ([0:2]), unions ([0,2]) and filters ([?(@.price < 10)]).
Is this the same as jq?
No. jq is a full transformation language with its own syntax; JSONPath only selects. To reshape the output rather than extract from it, use jq.
Why does my filter return nothing?
Check for a missing @ first. Inside a filter, @ is the current item, so write [?(@.price < 10)], not [?(price < 10)]. String comparisons also need quotes: [?(@.role == 'admin')].
Do all implementations agree?
No. JSONPath had no formal specification until RFC 9535 in 2024, so libraries differ on filters, unions and how they treat a missing key. Test any expression beyond a plain path against the library you ship.