JSONPath Tester

Type a JSONPath expression and see every match update live, along with the exact path of each one. Want to know the path to a value? Click it in the tree and the JSONPath is written for you. The tester supports RFC 9535 filters, slices, unions and functions, keeps large numbers exact, and runs entirely in your browser.

0 matches

          

What is JSONPath?

JSONPath is a query language for selecting values from a JSON document, much as XPath selects nodes in XML. An expression such as $.store.book[*].author starts at the root ($) and steps through keys, array indexes, wildcards and filters, and the result is the list of every value it reaches. Stefan Goessner described JSONPath in 2007. Each library then filled the gaps in its own way, until the IETF published a formal standard, RFC 9535, in February 2024.

You will meet JSONPath in Kubernetes (kubectl -o jsonpath), Postman and REST Assured test assertions, AWS Step Functions, API gateways, log pipelines and databases such as PostgreSQL. It only selects data. It never changes it.

JSONPath syntax cheat sheet

SyntaxMeaningExample
$Root of the document$
.keyChild member by name (dot notation)$.store.bicycle
['key']Child member by name (bracket notation); needed for spaces, dots and symbols$['first name']
[n]Array element by zero-based index$.store.book[0]
[-n]Index counted from the end$.store.book[-1]
* / [*]Wildcard: every member or element$.store.*
..Recursive descent: search at any depth$..price
[start:end:step]Array slice; end is exclusive, step may be negative$..book[0:2], [::-1]
[a,b]Union of several indexes or names$..book[0,2], $['a','b']
[?expr] / [?(expr)]Filter: keep children where expr is true$..book[?@.price < 10]
@The current item inside a filter[?(@.isbn)]
== != < <= > >=Comparisons on numbers, strings, true/false/null[?@.category == 'fiction']
&& || !And, or, not; group with parentheses[?@.price < 10 && !@.isbn]
length() count()Length of a string, array or object; number of nodes[?length(@.title) > 15]
match() search()Regex: whole-string match or substring search[?match(@.author, 'J.*')]
value()The single value of a query that returns one node[?value(@..isbn) == '0-553-21311-3']
=~ /re/iJayway-style regex (extension, full match)[?(@.author =~ /.*rees/i)]

JSONPath examples on the bookstore document

These are the classic examples from Goessner's original article. Press Bookstore sample above and click a chip to run any of them. The sample has four books (Nigel Rees, Evelyn Waugh, Herman Melville, J. R. R. Tolkien) and a red bicycle.

ExpressionResult
$.store.book[*].authorThe authors of all books (4 strings)
$..authorEvery author key at any depth (the same 4)
$.store.*Everything in the store: the book array and the bicycle object
$.store..priceEvery price in the store: 8.95, 12.99, 8.99, 22.99, 19.95
$..book[2]The third book (Moby Dick)
$..book[-1]The last book (The Lord of the Rings)
$..book[0,1] / $..book[:2]The first two books
$..book[?(@.isbn)]Books that have an isbn (Moby Dick, The Lord of the Rings)
$..book[?(@.price<10)]Books cheaper than 10 (Sayings of the Century, Moby Dick)
$..book[?@.category == 'fiction' && @.price < 10].title"Moby Dick"
$..*Every member and element in the document (27 nodes)

JSONPath arrays and arrays of objects

Most real queries go into an array of objects: users, items, orders. Four patterns cover nearly all of them:

$.users[0].email                      # one field of one element
$.users[*].email                      # that field from every element
$.users[?@.active == true].email      # only elements that pass a filter
$.users[?@.roles[?@ == 'admin']].name # filter on an array inside each element

Slices work like Python: [1:3] returns indexes 1 and 2, [-2:] the last two, and [::-1] the whole array reversed. An index past the end is not an error. It just matches nothing. A comparison such as @.price < 10 is quietly false when price is missing or is a string, so a filter never fails halfway through an array with mixed records.

One rule surprises people: in RFC 9535, both sides of a comparison must be a singular query (names and indexes only). [?@.tags[*] == 'x'] is therefore rejected. Nest a second filter instead: [?@.tags[?@ == 'x']] is true when any tag equals 'x'.

Escaping special characters in JSONPath keys

Dot notation only works for plain identifiers. For any other key, use bracket notation with a quoted name:

Key in the JSONJSONPath
first.name$['first.name'] ($.first.name would look for name inside first)
with space, content-type, @id$['with space'], $['content-type'], $['@id']
it's$['it\'s'] or $["it's"]
C:\temp$['C:\\temp']
café$.café or $['caf\u00e9']
Kubernetes annotation kubernetes.io/change-causekubectl: {.metadata.annotations.kubernetes\.io/change-cause}

The paths this tester outputs are already escaped correctly. Choose bracket path style to get RFC 9535 normalized paths such as $['store']['book'][0]. Each one identifies exactly one value, and it is the same in every compliant implementation.

JSONPath finder: generate a path by clicking

To find the JSONPath of a value in a large document, open the Tree tab and click the value. Its path goes into the expression box and is evaluated straight away. Tick Use [*] for array indexes to turn $.data.items[3].sku into $.data.items[*].sku, which selects the field from every element. That is usually the expression you want for an extractor, a test assertion or a kubectl template. Nodes matched by the current expression are highlighted in the tree.

RFC 9535 vs Goessner JSONPath

TopicGoessner (2007) and older librariesRFC 9535 (2024)
Filter syntax[?(@.price < 10)][?@.price < 10]; the parenthesised form is still valid
Script expressions[(@.length-1)] evaluated JavaScriptNot allowed; use [-1]
RegexLibrary-specific (=~ in Jayway)match() and search() with I-Regexp (RFC 9485)
Length.length or .length() in some librarieslength() inside filters only
QuotesVariesSingle or double quotes, with JSON-style escapes
Missing keys in comparisonsVaries, sometimes an error"Nothing": comparisons are false, and only Nothing == Nothing is true
Result pathsLibrary-specific formatNormalized paths, e.g. $['store']['book'][0]

This tester implements RFC 9535 and also accepts ?() filters, (@.length-N), Jayway =~, and kubectl-style {.items[*]} templates, so you can paste expressions from older documentation unchanged.

JSONPath vs jq vs JMESPath

JSONPathjqJMESPath
Cheap book titles$..book[?@.price<10].title.. | .book? // empty | .[] | select(.price<10) | .titlestore.book[?price < `10`].title
PurposeSelect valuesFull transformation languageSelect and reshape
StandardRFC 9535jq manual (one main implementation)JMESPath specification
Recursive search....No
Where you meet itkubectl, Postman, Jayway, PostgreSQLShell scripts, CI pipelinesAWS CLI --query, Azure CLI

Try the same data in the jq playground, the JMESPath playground or the JSONata playground, which can also reshape and aggregate JSON.

JSONPath in Python, JavaScript, Go, Java, PHP and PostgreSQL

Python JSONPath (jsonpath-ng and python-jsonpath)

# pip install jsonpath-ng
from jsonpath_ng.ext import parse          # .ext adds filter support
expr = parse("$.store.book[?price < 10].title")
titles = [m.value for m in expr.find(data)]
paths  = [str(m.full_path) for m in expr.find(data)]

# pip install python-jsonpath   (follows RFC 9535)
import jsonpath
jsonpath.findall("$.store.book[?@.price < 10].title", data)

JavaScript (jsonpath-plus)

import { JSONPath } from "jsonpath-plus";
JSONPath({ path: "$..book[?(@.price < 10)].title", json: data });
JSONPath({ path: "$..book[?(@.isbn)]", json: data, resultType: "path" });

Go JSONPath

// Kubernetes template syntax: k8s.io/client-go/util/jsonpath
j := jsonpath.New("authors")
if err := j.Parse("{.store.book[*].author}"); err != nil { log.Fatal(err) }
j.Execute(os.Stdout, data)               // data from json.Unmarshal into interface{}

// Goessner / RFC-style syntax: github.com/ohler55/ojg/jp
x, err := jp.ParseString("$..book[?(@.price < 10)].title")
titles := x.Get(data)                    // []any

Java (Jayway JsonPath)

// com.jayway.jsonpath:json-path
List<String> authors = JsonPath.read(json, "$.store.book[*].author");
List<Map<String, Object>> cheap = JsonPath.read(json, "$..book[?(@.price < 10)]");

PHP JSONPath

// composer require softcreatr/jsonpath
use Flow\JSONPath\JSONPath;
$titles = (new JSONPath($data))->find('$..book[?(@.price < 10)].title')->getData();

PostgreSQL jsonpath

PostgreSQL 12 and later implement the SQL/JSON path language. It looks like JSONPath, but filters come after the step, with ? (...), and strings use double quotes:

SELECT jsonb_path_query(doc, '$.store.book[*] ? (@.price < 10).title') FROM shop;
SELECT jsonb_path_query_array('{"a":[1,2,3]}', '$.a[*] ? (@ > 1)');   -- [2, 3]
SELECT * FROM shop WHERE doc @? '$.store.book[*] ? (@.category == "fiction")';
-- also: $.a[last], $.a[0 to 2], like_regex, exists(...), lax / strict modes

kubectl jsonpath examples

kubectl get pods -o jsonpath='{.items[*].metadata.name}'
kubectl get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.phase}{"\n"}{end}'
kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="InternalIP")].address}'
kubectl get secret db -o jsonpath='{.data.password}' | base64 -d

To test a kubectl template here, save the output of kubectl get pods -o json, paste it as the input, and paste the template (with or without the braces) as the expression. range and end are kubectl template features rather than JSONPath, so test the path inside them.

Why test JSONPath here

Frequently asked questions

What is JSONPath?

JSONPath is a query language for selecting values from a JSON document, in the way XPath selects parts of XML. An expression such as $.store.book[*].author starts at the root ($) and walks through keys, array indexes, wildcards and filters. It was described by Stefan Goessner in 2007 and standardised as RFC 9535 in 2024.

How do I filter an array of objects with JSONPath?

Use a filter selector with @ for the current item: $.store.book[?(@.price < 10)] or, in RFC 9535 form, $.store.book[?@.price < 10]. Combine conditions with && and ||, negate with !, and test that a key exists with [?(@.isbn)]. Add .title after the filter to return one field from each matching object.

How do I get the length of an array in JSONPath?

Standard JSONPath has no .length property in a path. Inside a filter, RFC 9535 provides length(), for example $.orders[?length(@.items) > 2]. To count matches, look at the match count of a query like $.orders[*], or use count() inside a filter. Some libraries, such as Jayway JsonPath, add their own $.orders.length() function.

How do I escape a dot, space or quote in a JSONPath key?

Use bracket notation with a quoted name: $['first.name'] or $['with space']. Inside single quotes, escape a single quote as \' (for example $['it\'s']) or switch to double quotes: $["it's"]. A backslash is written as \\. kubectl is different and uses a backslash before the dot: {.metadata.annotations.kubernetes\.io/change-cause}.

What is the difference between JSONPath and jq?

JSONPath only selects existing values and returns a list of matches, which is why it is embedded in tools like Kubernetes, Postman and databases. jq is a full programming language for the command line that can also reshape, compute and build new JSON. Use JSONPath when a tool asks for a path, and jq when you need to transform data.

Why does my expression work in one library but not another?

Before RFC 9535 there was no standard, so libraries differ on filter syntax, regex operators, functions such as .length() and the order of results. This tester follows RFC 9535 and also accepts the common Goessner and Jayway forms. If a library rejects an expression, check its documentation for which of these extensions it supports.

Is my JSON uploaded to a server?

No. Parsing and evaluating the JSONPath expression both run in JavaScript in your browser. The JSON never leaves your device, so you can safely test queries against API responses, Kubernetes manifests or logs that contain private data.

For a longer walkthrough, read the JSONPath tester guide.