How to use the jsonpath tester
- Paste a JSON document into the first box. It is checked as you type.
- Write a JSONPath query starting with $, such as $.store.book[?(@.price < 10)].title.
- Read the number of matches and each match with its full path and value.
- Copy the values as a JSON list, or copy the paths.
Syntax you can use
$ is the whole document. A dot and a name pick a key, and brackets with a quoted name do the same for keys with spaces or symbols. A number in brackets picks an item by position, counting from 0, and a negative number counts from the end. A slice such as [1:3] takes items from the start up to but not including the end, and a third number sets the step, so [::2] takes every second item and [::-1] reverses.
An asterisk takes every child. Two dots, as in $..price, look at every level below. A filter, written [?(@.price < 10)], keeps the items for which a test is true. Tests may compare with ==, !=, <, <=, > and >=, join with && and ||, negate with !, and check that a key exists. The functions length, count, match, search and value are supported.
How it runs
The query is read by a parser written for this tool and evaluated against the parsed JSON. It is never given to eval or to a function constructor, so a query cannot run code. Only a document's own keys are matched, so names like constructor or __proto__ do not reach built in properties. A query that does too much work stops with a message instead of freezing the page.
Numbers are read as ordinary JavaScript numbers, so integers longer than 15 digits can lose precision in the values shown. Not every JSONPath feature exists in every library, so check the syntax your own code uses. You can validate the document with the JSON formatter and validator, browse it in the JSON viewer, or describe its shape with the JSON schema generator. For plain text patterns, the regex tester is the tool.
Reading the results
Each match is shown with its normalized path, such as $['store']['book'][0]['title'], which is an exact address for that value. A query that is valid but matches nothing shows a clear message, and a query with a mistake shows what was expected and where. Matching tests for text, such as match and search, use a regular expression of up to 200 characters.
Assumptions and limits
- Queries use a subset of JSONPath: names, indexes, slices, wildcards, descent, filters and five functions.
- Dot names may contain letters, digits, underscores and hyphens. Use brackets for other characters.
- Comparisons between different types, such as a number and a string, are false.
- Values are parsed as JavaScript numbers, so very large integers can lose precision.
Frequently asked questions
How do I test a JSONPath expression?
Paste your JSON, type the expression in the query box, and read the matches below. Each one is shown with its path.
What does $..price mean?
It finds every key named price at any depth below the root.
How do I filter items by a value?
Use a filter such as $.items[?(@.price < 10)]. The @ stands for each item being tested.
Why does my query return nothing?
The query may be valid but match nothing, for example because a key is spelled differently or a value is a string where you compared a number.
Does the tool run my query as code?
No. A parser reads it and the evaluator only walks the data, so a query cannot execute anything.