All articles

How to Query JSON with JSONPath

Point at any value in a JSON document — no code required.

September 15, 2026 CheBit

Once JSON grows beyond a handful of keys, hunting through it by eye gets old fast. JSONPath is a compact query language that lets you point at the exact value — or values — you need, the same way XPath does for XML. Here's how it works and how to use it in seconds.

Full disclosure: this guide grew out of a problem we hit every week at work. We're developers, we format a lot of JSON, and we built the filtering and JSONPath features covered here to fix it. You'll learn the syntax below, then read the story of why we built it.

What is JSONPath?

JSONPath is a small expression language for selecting data inside a JSON document. Instead of reading a nested structure top to bottom, you write a path that walks straight to what you want. Every path starts with $, which represents the root of the document, then navigates with dots and brackets. First proposed by Stefan Goessner in 2007 as a JSON counterpart to XPath, the core syntax is now standardized as RFC 9535.

$.store.book[0].title

That expression reads as: "start at the root, go into store, then book, take the first item, and return its title." One line replaces a whole block of bracket-chained indexing.

Why use JSONPath?

  • Extract only what you need — pull a single field out of a large API response instead of copy-pasting the whole thing.
  • Filter without writing code — grab every item that matches a condition, like all books under a certain price.
  • Debug faster — confirm an endpoint actually returns the field you expect, in the shape you expect.

JSONPath syntax at a glance

Here are the operators that cover most day-to-day querying:

Expression What it selects
$.fieldThe field key of the root object
$.a.b.cThe value of a key three levels deep
$['field']Same as $.field, useful for keys with special characters
$[0]First item of a root array (negative indexes like [-1] count from the end)
$[*]Every item of an array
$.*Every value of an object
$..authorEvery author key anywhere in the document (recursive)
$[?(...)]Items that match a filter condition

Worked examples

Take this small "bookstore" document — the classic JSONPath example:

{ "store": { "book": [ { "title": "The Great Gatsby", "author": "F. Scott Fitzgerald", "price": 12.99, "category": "fiction" }, { "title": "Clean Code", "author": "Robert Martin", "price": 35.00, "category": "programming" }, { "title": "The Pragmatic Programmer", "author": "Andrew Hunt", "price": 45.50, "category": "programming" }, { "title": "The Hobbit", "author": "J.R.R. Tolkien", "price": 8.99, "category": "fiction" } ], "bicycle": { "color": "red", "price": 19.95 } } }

Here's what a few expressions return against it:

  • $.store.book[*].author— the author of every book, as a list of four strings.
  • $.store.book[0].title— "The Great Gatsby".
  • $.store.book[-1].title— "The Hobbit", the last book in the array.
  • $..author— every author value found at any depth.

Filtering with conditions

The real power comes from filter expressions, written inside [?(...)]. Use @ to refer to the current item, then compare against its fields:

$.store.book[?(@.price < 20)].title

That returns the titles of every book priced under 20 — "The Great Gatsby" and "The Hobbit". You can also test equality against strings:

$.store.book[?(@.category == 'fiction')]

Filters support the comparisons ==, !=, <, >, <= and >=, plus &&, || and ! to combine them. A regex match (=~) and in checks round out the set:

$.store.book[?(@.category == 'programming' && @.price > 40)].title
$.store.book[?(@.author =~ 'Martin')].title
$.store.book[?(@.category in ['fiction'])].title

The first matches any author containing "Martin" ("Clean Code"); the second returns the two fiction titles.

Why we built filtering and JSONPath into a formatter

Here's the honest backstory. We're developers, and a big part of our day is JSON — API responses, config files, logs, and the occasional multi-megabyte export. It started as a simple idea: build a clean online JSON formatter. The tools we'd find were either buried in ads or did exactly one thing, and even a nicely indented result didn't help when the document was long and we were still scrolling to find the field we actually cared about.

None of them could filter, so that was the first feature we added — a property filter that trims a large document down to just the fields you name, nested matches included. While we were building it, we kept running into JSONPath: a query language that felt similar to filtering but isn't quite the same. Filtering keeps whole fields; JSONPath points at a specific value — or every matching value — with an expression like $.store.book[?(@.price < 20)].title. Both turned out to be genuinely useful in different situations, so we added JSONPath and kept the filter.

Filtering gives you the shaped document; JSONPath gives you the specific value. We use both daily, and this guide shows you how — the JSONPath half below, with the filter one click away in the same Advanced panel.

How to query JSON in the Tool Vault formatter

You don't need to install anything — run JSONPath queries in the free, in-browser JSON Formatter:

  • 1.Paste your JSON into the input, then click Format (or load a file).
  • 2.Open the Advanced section at the top of the output panel.
  • 3.Type a JSONPath expression into the JSONPath field and click Query.
  • 4.Read the matched results below the field. Combine it with the collapsible Tree view to click any key and copy its exact path.

Want to keep whole fields instead of extracting values? The same Advanced panel has a property filter: type field names like name,id (or a dot path like user.email) and click Filter to trim the document down to just those keys, nested matches included. Filtering and JSONPath answer the same question from opposite ends — a shaped document versus a specific value — so we keep both open depending on the job.

The built-in JSONPath engine covers the common subset described above — root selectors, child access, wildcards, array indexes, recursive descent, and filter expressions — which handles the vast majority of day-to-day queries, not every edge case in RFC 9535. Because everything runs 100% client-side, your JSON never leaves your device — handy when the document contains real API responses or credentials. If you're new to JSON itself, start with our guide to formatting and validating JSON.

Frequently asked questions

What is JSONPath used for?

JSONPath lets you point at specific parts of a JSON document — a single value, a list of values, or values that match a condition — without writing any code. Developers use it to debug API responses, pull fields out of large documents, and validate that a payload contains the expected data.

Is JSONPath the same as XPath?

They're analogous, but JSONPath is for JSON while XPath is for XML. JSONPath uses $ for the document root and a mix of dot and bracket notation (such as $.store.book[0].title) to navigate objects and arrays, where XPath uses slash-separated element paths.

What JSONPath features does the Tool Vault formatter support?

It supports the core JSONPath subset — the root selector $, dot and bracket access, wildcards, array indexes (including negative), recursive descent (..field), and filter expressions like [?(@.price < 20)].

Ready to query your JSON?

Try the free, in-browser JSON Formatter — run JSONPath queries, filter properties, and explore a collapsible tree, all without uploading your data.

Query JSON now