JSONPath Syntax Explained With Practical Filter Examples

Learn JSONPath from the root $ to wildcards, slices, recursive descent and filters, with worked examples, RFC 9535 notes and how it compares with jq.

Updated September 29, 2026 6 min read

Use the free JSONPath TesterRun JSONPath queries with filters, slices and recursive descent

JSONPath turns up in more places than most developers expect. API testing tools use it to extract values from responses. Monitoring and alerting systems use it to pick a metric out of a JSON payload. Workflow and integration platforms use it to map fields from one system to another. Kubernetes' kubectl accepts JSONPath templates for its output. If you have ever needed "the IDs of all paid orders over 50" from a big JSON document, JSONPath is the one-line answer.

This guide walks through the syntax from the ground up with a single realistic example, explains the filter expressions that trip people up, notes where implementations differ, and shows when jq or plain code is the better tool.

The example document

All examples below query this order export:

{
  "orders": [
    { "id": "A-100", "status": "paid", "total": 120.5,
      "customer": { "country": "DE" },
      "items": [ { "sku": "TS-1", "qty": 2 }, { "sku": "MUG", "qty": 1 } ] },
    { "id": "A-101", "status": "refunded", "total": 35,
      "customer": { "country": "FR" },
      "items": [ { "sku": "MUG", "qty": 4 } ] },
    { "id": "A-102", "status": "paid", "total": 9.99,
      "customer": { "country": "DE" }, "coupon": "SPRING",
      "items": [] }
  ]
}

The building blocks

A JSONPath expression always starts at the root, written $, and then steps down into the document.

Syntax Meaning Example Result
$ The root document $ the whole object
.name or ['name'] A child by key $.orders the orders array
[n] Array item by index (0-based) $.orders[0].id "A-100"
[-1] Counting from the end $.orders[-1].id "A-102"
[a,b] Several indexes or keys $.orders[0,2].id "A-100", "A-102"
[start:end] A slice, end excluded $.orders[0:2].id "A-100", "A-101"
* Every child $.orders[*].id all three IDs
.. Recursive descent: any depth $..sku "TS-1", "MUG", "MUG"
[?( )] Filter see below

Bracket notation is required when a key contains spaces, dashes or dots: $['order-lines'] rather than $.order-lines.

Slices work like Python's: [start:end:step], with any part optional. [:2] means the first two items and [::2] every second item.

Recursive descent (..) is powerful but blunt. $..sku finds every sku anywhere in the document, including in places you did not expect. Prefer an explicit path when you know the structure.

Filters: selecting items by their content

Filters are where JSONPath earns its keep. Inside [?( )], the symbol @ means "the current item being tested".

Compare a value:

$.orders[?(@.status == "paid")].id

returns "A-100" and "A-102".

Combine conditions with && and ||:

$.orders[?(@.status == "paid" && @.total > 50)].id

returns only "A-100".

Test whether a key exists by naming it without a comparison:

$.orders[?(@.coupon)].id

returns "A-102", the only order with a coupon.

Filter on nested values or on array length:

$.orders[?(@.customer.country == "DE")].id
$.orders[?(@.items.length == 0)].id

The first returns "A-100" and "A-102"; the second returns "A-102", the order with no items.

Compare against another part of the document by using $ inside the filter, for example @.total > $.threshold if the document contains a threshold value.

Test expressions with our tool

The JSONPath Tester evaluates expressions live as you type, in your browser.

  1. Open the JSONPath Tester. Paste your data into JSON document, or click Load sample for the classic bookstore example.
  2. Type an expression into JSONPath expression. You can also click one of the example chips beneath it, such as $..book[?(@.price < 10)].title, and adapt it.
  3. Read the Result panel. Use Show to switch between Values, Paths (for example $.orders[0].id) and Paths + values.
  4. If the expression is invalid, the tool tells you what went wrong and at which character.
  5. Click Copy to take the result elsewhere.

Paths mode is especially useful when you plan to write code against the data: it tells you exactly where each match lives. The tester also supports regular expression matching with =~ (for example @.author =~ /tolkien/i), ! for negation, and a length() function.

Standards and dialects

JSONPath was first described informally by Stefan Goessner in 2007, and for years every library interpreted the details a little differently. In 2024 the IETF published RFC 9535, a formal standard. The core of the language ($, dot and bracket children, wildcards, slices, recursive descent and filters) is the same everywhere, but details vary:

  • RFC 9535 writes filters as ?@.price < 10; the parentheses used in older syntax are accepted as grouping.
  • Regular expressions are standardised as the functions match() and search(), while many libraries use =~ instead.
  • Some older libraries accept script expressions such as (@.length-1), which the standard does not include.

If your expression works in one product and not another, check that product's documentation for its dialect. Stick to the common core for portability.

JSONPath, jq or code?

jq is a complete language for transforming JSON on the command line. The same query in jq is:

jq '.orders[] | select(.status == "paid" and .total > 50) | .id' orders.json

jq can also reshape, group and compute, which JSONPath cannot. Use jq for scripts and data wrangling, JSONPath where a tool asks for a path expression.

Plain code is clearest inside an application. In JavaScript the same query is:

const ids = data.orders
  .filter((o) => o.status === "paid" && o.total > 50)
  .map((o) => o.id);

It is type-checked, debuggable and needs no extra library. JSONPath is best when the query must be stored as configuration or typed by a user.

Troubleshooting

No matches, but you expected some

Check the case of keys (Status and status differ), check whether the value is a number or a string (@.total > 50 does not match "120.5"), and make sure you started from $.

Too many matches

.. probably reached into nested objects with the same key. Replace it with the explicit path.

Keys with special characters

Use bracket notation with quotes: $['customer-info']['vat-id'].

Validate the document first

If the JSON itself is invalid, no expression can work. Check it with the JSON Validator, browse its structure in the JSON Viewer, and when writing regex filters, test the pattern alone in the Regex Tester.

Frequently asked questions

What does the $ mean in JSONPath?

$ is the root of the document. Every absolute JSONPath expression starts with it, and inside a filter it lets you refer back to values elsewhere in the document.

What is the difference between @ and $ in a filter?

@ is the current item being tested by the filter; $ is the document root. @.price < $.limit compares each item's price with a single limit stored at the top level.

Are JSONPath array indexes zero-based?

Yes. [0] is the first item and [-1] is the last. Slices exclude the end index, so [0:2] returns the first two items.

Is JSONPath the same as XPath?

No, but it was inspired by XPath. JSONPath is much smaller and designed for JSON, with no axes or node types. XPath is for XML.

Why does my filter work in one tool and fail in another?

Implementations differ in details such as regex syntax, function names and whether parentheses are required. RFC 9535 is standardising these, but older tools still use their own dialects.

Try it now: JSONPath Tester

Loading tool…