JSONPath Tester

Test JSONPath expressions on JSON data

JSON input
1
2
3
4
5
6
7
8
Processed locally in your browser
Understanding JSONPath
TL;DR

JSONPath is a query language for extracting data from JSON documents — like XPath for XML. Navigate nested objects and arrays without code.

What is JSONPath?

JSONPath is a query language for extracting specific values from JSON documents. It provides a concise syntax for navigating nested objects and arrays, filtering elements by conditions, and selecting multiple values at once — all without writing procedural code.

Think of JSONPath as the JSON equivalent of XPath for XML, or CSS selectors for HTML. Instead of writing loops and conditional statements to traverse a JSON tree, you write a single expression that describes the data you want. The JSONPath engine handles the traversal and returns the matching values.

JSONPath is especially valuable when working with API responses. Modern APIs often return deeply nested JSON structures — a single response might contain dozens of nested objects and arrays. JSONPath lets you surgically extract the fields you need without manually navigating every level of nesting.

JSONPath Syntax

Every JSONPath expression starts with $, which represents the root of the JSON document. From there, you chain operators to navigate deeper into the structure.

Syntax Reference

OperatorDescriptionExample
$Root object$ returns the entire document
.keyChild member$.store accesses the store property
..keyRecursive descent$..price finds all price fields at any depth
[0]Array index$.books[0] returns the first book
[*]Wildcard$.books[*] returns all books
[0:3]Array slice$.books[0:3] returns books at index 0, 1, 2
[?(@.price<10)]FilterReturns elements where condition is true
@Current elementUsed inside filter expressions

Dot notation (.key) accesses a named property of the current object. You can chain dots to traverse multiple levels:

$.store.address.city

This navigates from root → storeaddresscity. If any intermediate key does not exist, the result is empty.

Array elements are accessed by zero-based index ([0], [1], etc.) or by wildcard ([*] for all elements). Negative indices count from the end: [-1] returns the last element.

Array slicing follows the [start:end:step] pattern, similar to Python:

  • [0:3] — Elements at indices 0, 1, 2
  • [1:] — All elements from index 1 onward
  • [::2] — Every other element

Recursive Descent

The .. operator searches recursively through the entire document tree. $..price finds every property named price, regardless of how deeply it is nested. This is powerful but can be slow on large documents because it traverses every node.

Filter Expressions

Filters use the syntax [?(@.condition)] where @ refers to the current element. Filters support comparison operators (==, !=, <, >, <=, >=) and logical operators (&&, ||).

Examples:

  • $.books[?(@.price < 10)] — Books cheaper than 10
  • $.books[?(@.author == 'Tolkien')] — Books by Tolkien
  • $.books[?(@.price < 20 && @.category == 'fiction')] — Cheap fiction books

JSONPath Tree Traversal

JSONPath Tree Navigation A tree diagram showing how the expression $.store.books[0].title traverses from root ($) through store, books array, first element [0], to the title field. $.store.books[0].title $ store meta books [] city [0] [1] title price Result "The Hobbit" Traversed path Not selected

JSONPath vs jq

While JSONPath and jq both query JSON, they serve different contexts:

FeatureJSONPathjq
EnvironmentLibraries, browsers, APIsCommand line
Syntax styleDot notation ($.store.books)Pipe-based (.store.books)
TransformationRead-only (query)Read + transform + construct
ComplexitySimple queriesComplex data pipelines
StandardRFC 9535 (2024)De facto CLI standard
Best forAPI testing, config queriesLog processing, data pipelines

JSONPath is ideal when you need to extract data from JSON without transforming it — for example, testing API responses or building config queries. jq is more powerful when you need to reshape, filter, aggregate, or construct new JSON structures.

Common Use Cases

  • API debugging: Paste a complex API response and write JSONPath queries to validate that expected fields exist and contain correct values
  • Configuration extraction: Pull specific values from large JSON config files without parsing the entire structure in code
  • Test assertions: Automated tests use JSONPath to assert specific values in API responses, making test code more readable than nested property access
  • Data transformation pipelines: Extract specific fields from JSON documents as part of ETL workflows
  • Documentation: JSONPath expressions in API docs show consumers exactly how to access specific response fields

Try These Examples

Filter Books by Price Valid

This JSONPath expression navigates to the 'store' object, filters the 'books' array for items where price is less than 10, and returns only the 'title' field. The @ symbol refers to the current element being evaluated.

$.store.books[?(@.price < 10)].title
Path to Non-Existent Key Valid

Querying a path that does not exist in the JSON document returns an empty result set — not an error. This is useful for safely checking whether a key exists without crashing.

$.nonexistent