JSONPath is a compact query language for JSON documents, modelled on XPath for XML. An expression such as $.store.book[*].author describes a path from the root of a document down to the nodes you care about, and returns every value that matches. This tester evaluates JSONPath expressions live against your own JSON, entirely in the browser, so you can iterate on a query without writing any code.
How it works
A JSONPath expression is a sequence of steps applied left to right, starting from the root $. Each step takes the set of nodes selected so far and produces a new set:
.nameor['name']selects a child property.[0]selects an array element by index; negative indices count from the end.[0,2]is a union that selects several indices at once.[1:4]is a slice; an optional third value[1:9:2]sets the step.*is a wildcard that selects every child of an object or array...is recursive descent: it matches the current node and everything nested below it, so$..pricefinds everypriceanywhere in the tree.[?(@.field op value)]is a filter that keeps only elements where the condition holds. Here@is the element being tested.
The evaluator threads a list of candidate nodes through each step and collects whatever survives the final step as the result array.
Example
Given a store document with a book array, the expression $.store.book[?(@.price < 10)].title first walks to store, then book, keeps the books whose price is under 10, then reads each surviving book’s title. The result is the list of cheap-book titles. Change the comparison to >= 10 and the result flips to the expensive titles instead.
Tips
- Build a path one segment at a time. If
$.store.bookreturns the array but$.store.book[*].titlereturns nothing, the problem is thetitlekey, not the earlier path. - Use
..when you do not know the exact depth of a value —$..idwill surface everyidregardless of nesting. - Filters compare against literals: numbers (
10), quoted strings ('fiction'),true,false, ornull. Use=~ /pattern/ito match a string field against a regular expression.