Blog

How to test JSONPath expressions

The JSONPath syntax you'll use most, worked examples against a sample document, and how to try expressions in the free JSONPath tester.

February 7, 2026

You call an API, get back 4,000 lines of JSON, and you need one field that lives five levels down inside an array. You could write a loop. Or you could write one short expression and be done before your coffee gets cold.

What is JSONPath

JSONPath is a query language for JSON, much as XPath is for XML. One short expression pulls specific values, arrays or objects out of a document. Stefan Goessner proposed it in 2007, and the IETF published it as a standard in 2024 as RFC 9535.

You describe the path to the data, and JSONPath hands back whatever matches. No nested loops, no if (data && data.store && ...) chains.

JSONPath syntax basics

Every expression starts with $, the root of the document. From there you step into the structure with dots and brackets:

SyntaxMeaning
$The root
.keyChild by name (dot notation)
['key']Child by name (bracket notation)
..Recursive descent, searching every level
*Wildcard: every child
[n]Array index, starting at 0
[start:end]Array slice
[?(@.expr)]Filter
@The current element, used inside filters

The examples below use this small bookshop. Every developer bookshelf has at least two of these:

JSON
{
  "store": {
    "name": "Tech Books",
    "books": [
      {
        "title": "Clean Code",
        "author": "Robert C. Martin",
        "price": 33.99,
        "tags": ["programming", "best-practices"]
      },
      {
        "title": "The Pragmatic Programmer",
        "author": "David Thomas",
        "price": 42.5,
        "tags": ["programming", "career"]
      },
      {
        "title": "Design Patterns",
        "author": "Gang of Four",
        "price": 39.99,
        "tags": ["programming", "architecture"]
      }
    ]
  }
}

Common JSONPath examples

Nested properties

Dot notation walks down the hierarchy, and an index picks an array item:

Text
$.store.name            → "Tech Books"
$.store.books[0].title  → "Clean Code"
$.store.books[2].price  → 39.99

Wildcards

* selects every element at that level. On an array it returns one result per item:

Text
$.store.books[*].title  → ["Clean Code", "The Pragmatic Programmer", "Design Patterns"]
$.store.books[*].price  → [33.99, 42.5, 39.99]

Array slices

Slices select a range, like Python: the start is included and the end isn’t. A negative number counts from the end.

Text
$.store.books[0:2].title  → ["Clean Code", "The Pragmatic Programmer"]
$.store.books[-1:].title  → ["Design Patterns"]

Filters

A filter keeps the elements that match a condition, with @ standing for the element being tested:

Text
$.store.books[?(@.price < 40)]                → the Clean Code and Design Patterns objects
$.store.books[?(@.author == 'David Thomas')]  → the Pragmatic Programmer object
$.store.books[?(@.tags[0] == 'programming')]  → all three books

RFC 9535 also allows filters without the parentheses, as in [?@.price < 40]. Most libraries accept the older form shown above.

Recursive descent

.. searches every level of the document. Use it when you know a key’s name but not where it sits:

Text
$..title  → ["Clean Code", "The Pragmatic Programmer", "Design Patterns"]
$..price  → [33.99, 42.5, 39.99]

JSONPath and XPath

JSONPath borrows its ideas from XPath, so if you know one, the other will feel familiar:

ConceptXPathJSONPath
Root/$
Child/. or []
Recursive descent//..
Filter[condition][?(condition)]

The main difference is the data model. XPath handles XML’s attributes, namespaces and text nodes. JSONPath only has to deal with objects, arrays and values.

How to use the JSONPath tester

  1. Open the JSONPath tester and paste your JSON into JSON data.
  2. Type an expression into JSONPath expression, or pick one of the examples under Try.
  3. Select Evaluate or press Enter. A single match is shown as its value, several matches as an array, and otherwise you see “No matches found.” Invalid JSON shows the parser error.
  4. Copy the results, or Clear to start again.

The tester runs in your browser and supports the core of JSONPath: $, dot notation, array indexes such as books[0], and wildcards such as books[*] and store.*. That covers the nested property and wildcard examples above. Bracket notation, slices, negative indexes, filters and recursive descent aren’t supported yet. To test those, use a full library such as JSONPath-Plus.

Where JSONPath is used

  • API testing tools use it to pull values out of responses for assertions.
  • Data pipelines use it to extract fields from large JSON documents.
  • Kubernetes’ kubectl accepts JSONPath templates with -o jsonpath.
  • Monitoring and automation tools use it to read values from logs and webhook payloads.

Before you put an expression into code or configuration, test it against real sample data so you know it selects what you expect.

Need data from a webpage as JSON?

PulpMiner turns any public page into structured JSON and can save it as a live API. See it work on a demo page, no sign-up.

Try it on a demo page