DevToolCase
Sign in Sign in

Test a JSONPath expression

Run a JSONPath expression on JSON: the matching values and their paths, with filters such as [?(@.price < 10)] and a clickable cheat sheet.

Share this result

Encrypted in your browser. The key stays in the link, after “#”: only the people you give it to can read it, not even DevToolCase.

The link works for

Sign in for longer links or links without expiry, and to find them in your account.

Cheat sheet

Click an expression to try it on the bookstore example.

  • the author of every book
  • every “author” key, at any depth
  • everything in the store: the books and the bicycle
  • every price, books and bicycle
  • the third book (indexes start at 0)
  • the last book
  • the first two books
  • a slice: the second and third books, the end index excluded
  • the books that have an ISBN
  • the books under 10
  • the titles of the fiction books over 10
  • every value of the document

Runs entirely in your browser: nothing you type is sent or stored.

What is JSONPath?

JSONPath is to JSON what XPath is to XML: a short expression that points at values in a document, wherever they are. $.store.book[*].author reads “the author of every book of the store”. Proposed by Stefan Goessner in 2007, it was standardized in 2024 as RFC 9535.

Paste your JSON, type an expression, and see the values it selects, how many there are and the normalized path of each one, such as $['store']['book'][0]['author'], which points at exactly one value. Click an expression of the cheat sheet to try it on the bookstore example.

JSONPath syntax

SyntaxSelects
$the root of the document
@the current value, in a filter
.name or ['name']a key; the brackets allow spaces and dashes
..namea key at any depth (recursive descent)
*, [*]every key or item
[0], [-1:]an item by its index, from 0; the last item
[0,1], [1:3]several items; a slice, the end excluded
[?(@.price < 10)]the items that pass a filter

Filters

A filter keeps the items for which its condition is true, @ being the item tested.

  • Compare with <, <=, >, >=, ==, === and !=, strings in quotes: [?(@.category == 'fiction')].
  • Combine with &&, || and !, as in [?(@.price > 10 && @.isbn)].
  • Test whether a key exists with [?(@.isbn)].

Filters run in a sandboxed interpreter, never as real JavaScript code: an expression from a shared link cannot do anything but read your JSON.

JSONPath, RFC 9535 and jq

This tool follows Goessner’s original syntax, the one of most libraries (jsonpath-plus in JavaScript, Jayway in Java). RFC 9535 keeps the same paths but writes filters without parentheses, $.store.book[?@.price < 10], and adds functions such as length() and match(). Expressions without filters give the same result in both, and the normalized paths shown here are those of the RFC.

jq is another language, a command-line tool that also transforms JSON: .store.book[] | select(.price < 10). JSONPath only selects values, but its short syntax fits in a configuration file or a test assertion.

Where JSONPath is used

  • Kubernetes, to pick fields from kubectl output (without the $, between braces).
  • API tests, such as jsonPath("$.name") with Spring MockMvc, JMeter’s JSON extractor or SoapUI assertions.
  • API clients such as Insomnia, to filter a large response.
  • AWS Step Functions and many integration tools, to map the fields of a message.
kubectl get pods -o jsonpath='{.items[*].metadata.name}'

Is your JSON on a single line? Format it first. To type it in your code, generate its TypeScript interfaces.

Add this browser’s favorites to your account?

This browser has 0 favorites that your account does not have:

Either way, this browser keeps its favorites: you find them again after signing out.