JSONPath Tester

Run a JSONPath query in the browser. To pretty-print the document, use the JSON formatter

What you can query

JSONPath picks values out of a JSON document. This page runs a practical subset and returns every match as JSON. To tidy the document first, use the JSON formatter.

How to use it

  1. Paste JSON in the top box and a path in JSONPath. The path starts as $.
  2. Convert runs the query. The line beside the path says how many matches came back.
  3. Show Example loads {"store":{"book":[{"author":"Nigel","price":8},{"author":"Evelyn","price":12}],"bicycle":{"price":19}}} and the path $.store.book[*].author. The result is a JSON array of Nigel and Evelyn, and the count is 2.
  4. The chips fill the same document if the box is empty. $.store.book[?(@.price<10)].author returns Nigel. $..price returns 8, 12 and 19.
  5. Clear All empties the document, sets the path back to $, and clears the count. Copy Result copies the JSON matches.

Paths this page accepts

$ is the root. .key and ['key'] read a property. [n] reads one index, and a negative index counts from the end. [*] reads every element or property. [start:end:step] slices an array, with end excluded. [0,2] picks those indexes. ..key walks every nested object and collects that key.

A filter has the form [?(@.price<10)] or [?(@.author=='Nigel')]. The comparisons are ==, !=, <, >, <= and >=. Text is compared exactly. Ordering applies to numbers. The filter runs on an array. An unknown path, or JSON that does not parse, is an error. Zero matches is a valid empty array.

Where people use it

  • Pulling one field from every object in a list.
  • Keeping the rows whose price is under a number.
  • Finding every price, including ones nested in different objects.

Questions

Why is the result an array when there is one author?

Every query returns the list of matches, so one hit is still a one-element array.

Does a script expression work?

Filters are one comparison on @ and its fields. Other script syntax stops with an error.