How to Test JSONPath Expressions
JSONPath is to JSON what XPath is to XML: a compact way to select values from a document. It's used in API tooling, config, and testing frameworks. Here's the syntax you'll actually use, with examples you can run.
The building blocks
Every expression starts at the root, $, then drills in:
$.store.book— child access by name (also$['store']['book'])$.store.book[0]— array index;[-1]counts from the end$.store.book[*]— every element (wildcard)$..author— recursive descent: everyauthorat any depth
Slices and unions
Ranges and multiple selections work inside the brackets:
$.book[0:2]— a slice, elements 0 and 1 ([start:end:step])$.book[0,2]— a union, elements 0 and 2
Filters
Filters keep only the elements that match a condition, written with @ for the current element:
$.store.book[?(@.price < 15)].title
That selects the titles of every book cheaper than 15. Filters support ==, !=, <, <=, >, and >=, plus a bare @.isbn test that keeps elements where the field exists and is truthy.
Putting it together
$..book[?(@.price >= 22)].title reads as: find every book anywhere in the document, keep those priced 22 or more, and return their titles.
Related
Working with JSON? See JSON Diff to compare two documents and JSON Formatter to validate one.
Try it
Paste your JSON, type an expression, and watch the matches update live — everything runs in your browser, nothing uploaded.