JSONPath syntax cheat sheet
| Syntax | Meaning | Example |
|---|---|---|
$ |
The root object | $ |
.key or ['key'] |
Child property | $.store.bicycle or $['store']['bicycle'] |
.. |
Recursive descent: search at any depth | $..price |
* |
Wildcard: all properties or items | $.store.book[*] |
[n] |
Array index (0-based, negatives count from the end) | $..book[0] |
[a,b] |
Several indexes or keys | $..book[0,2] |
[start:end:step] |
Array slice (end excluded) | $..book[1:3], $..book[-2:] |
[?(expr)] |
Filter: keep items where expr is true | $..book[?(@.price < 10)] |
@ |
The current item inside a filter | @.isbn, @.price |
Filter expressions
- Compare:
$..book[?(@.category == 'fiction')] - Combine:
$..book[?(@.price > 5 && @.price < 15)] - Property exists:
$..book[?(@.isbn)] - Nested property:
$..orders[?(@.customer.country == 'US')]
JSONPath in kubectl
Kubernetes uses JSONPath templates to pull fields out of API objects:
# Names of all pods
kubectl get pods -o jsonpath='{.items[*].metadata.name}'
# Image of every container, one per line
kubectl get pods -o jsonpath='{range .items[*]}{.spec.containers[*].image}{"\n"}{end}'
kubectl leaves out the leading $ and wraps expressions in braces. Test the inner path here first,
with $ added in front.
JSONPath in code
JavaScript
// npm install jsonpath-plus
import { JSONPath } from 'jsonpath-plus';
const titles = JSONPath({ path: '$.store.book[?(@.price < 10)].title', json: data });
Python
# pip install jsonpath-ng
from jsonpath_ng.ext import parse
titles = [m.value for m in parse("$.store.book[?price < 10].title").find(data)]
PostgreSQL
-- PostgreSQL has SQL/JSON path built in
SELECT jsonb_path_query(doc, '$.store.book[*] ? (@.price < 10).title')
FROM inventory;
Data stuck inside an escaped string? Run it through JSON Unescape first.
Frequently asked questions
What is JSONPath?
JSONPath is a query language for selecting values from a JSON document, much like XPath for XML. It was introduced by Stefan Goessner in 2007 and standardized as RFC 9535 in 2024. It is used in Kubernetes (kubectl -o jsonpath), AWS Step Functions, API testing tools like Postman, and many databases.
How do I filter an array with JSONPath?
Use a filter expression in brackets: $.items[?(@.price < 10)]. Inside the filter, @ refers to the current item. You can combine conditions with && and ||, compare with ==, !=, <, <=, > and >=, and test whether a property exists with [?(@.isbn)].
What is the difference between JSONPath and jq?
JSONPath only selects values from a document. jq is a full programming language that can also transform, reshape and compute new JSON. Use JSONPath when a tool asks for it (kubectl, Postman, cloud services) and jq for shell scripting.
What are "Paths" and "Pointers" in the results?
Paths shows the normalized JSONPath of each match, such as $['store']['book'][2], so you can target it precisely. Pointers shows the same location as an RFC 6901 JSON Pointer, such as /store/book/2, which is used by JSON Patch and JSON Schema.
Are filter expressions safe to run here?
Yes. Expressions are evaluated by a sandboxed interpreter that only supports JSONPath operators. They can’t run arbitrary JavaScript, and your JSON never leaves the browser.