JSONPath tester

Test a JSONPath expression (RFC 9535) against your JSON and see every match, with its path.

loading JSONPath tester
About this tool

What is a JSONPath tester?

JSONPath is a small query language for JSON. You write an expression such as $.store.book[*].author and get back every value in the document that the expression selects, the way XPath does for XML. It is handy when you need one field from a large API response, when you write a rule for a tool that accepts JSONPath, or when you want to check a filter before it goes into a config file.

This tester follows RFC 9535, the standard that finally pinned down the syntax: names, wildcards, the recursive descent .., array indexes (negative ones too), slices like [:2], unions like [0,1], filters like [?@.price < 10] and the functions length, count, match, search and value. You paste a JSON document, type an expression, and the matches appear as you type. A switch lets you see the matched values, their normalized paths, their JSON Pointers, or the path and the value together. Everything runs in your browser, so the document you paste is never sent anywhere.

Be aware that JSONPath existed for many years before the RFC. Libraries differ on filter syntax, on what a missing key returns and on extras such as script expressions. If a query behaves differently in your own code, check which library it uses. This page answers the way the standard says.

How to test a JSONPath expression

  1. Paste your JSON into the JSON field. The "Example" button loads a small bookstore document.
  2. Type the expression in the JSONPath field. It must start with $, which stands for the whole document.
  3. Read the result on the right. The counter says how many matches were found.
  4. Choose what to show: "values" lists the matched data, "paths" the location of each match, "pointers" the same location as a JSON Pointer, and "path + value" gives both.
  5. Copy or download the result as a JSON file.
  6. If the field turns red, read the message. It says what the parser did not understand and, for broken JSON, the line and column.

Examples

All examples use the bookstore document from the Example button: four books under store.book and a bicycle next to them.

Filter by price

Expression:

$.store.book[?@.price < 10].title

Result in "values" mode:

[
  "Sayings of the Century",
  "Moby Dick"
]

Last item, first items and search inside a string

$..book[-1].title returns the last book, ["The Lord of the Rings"]. $..book[:2].title returns the first two titles. $.store.book[?match(@.author, "^[EN].*")].author keeps authors whose name starts with E or N:

[
  "Nigel Rees",
  "Evelyn Waugh"
]

match has to fit the whole string, while search looks for the pattern anywhere. That is why $.store.book[?search(@.title, "of")].title finds three titles.

Paths and pointers

For $.store.bicycle.color the three views are:

["red"]
["$['store']['bicycle']['color']"]
["/store/bicycle/color"]

The pointer form is what JSON Patch uses to say where to change a document.

Common mistakes

  • Forgetting the $. An expression like store.book is rejected. Start with $.
  • Writing $.store.[. A dot before a bracket is not valid. Use $.store.book[0] or $.store['book'].
  • Expecting an error when nothing matches. A valid expression that selects nothing returns an empty list and a count of 0. The tool tells you that it matched nothing.
  • Broken JSON. Single quotes, trailing commas and comments are not JSON. The error shows the line and column. JSON Prettify can help you find the culprit.
  • Filters without @. Inside [? ], @ is the item being tested. Write @.price, not price.
  • Comparing numbers with strings. @.price < 10 compares numbers. "10" in quotes is text, and a comparison between different types is simply false.
  • Using a feature of an older library. Things such as script expressions in older implementations are not part of the standard and are not evaluated here.

Frequently asked questions

Which JSONPath syntax does this tool use?

The one in RFC 9535, implemented with the json-p3 library. Filters, slices, wildcards, descendants, unions and the five standard functions are supported.

Does it change or save my JSON?

No. It only reads the document and shows the matches. The text stays in the page, and the expression settings are the only thing remembered between visits.

How is JSONPath different from jq?

JSONPath selects values and shows where they are. jq is a full language: it can also compute, reshape and build new JSON. When you need to transform the data, try the jq tester.

Can I get the location of each match?

Yes. Switch the view to "paths" for normalized paths like $['store']['book'][0]['title'], or to "pointers" for JSON Pointers like /store/book/0/title.

Report a problem