jsonjsonpathqueryapi

JSONPath: Query JSON Data Like a Pro

·6 min read

What is JSONPath?

JSONPath is a query language for JSON, analogous to XPath for XML. It lets you select values from a JSON document using a compact expression. JSONPath is built into API testing tools like Postman, used in AWS Step Functions, Kubernetes configs, and many data pipeline frameworks.

JSONPath Syntax Basics

Every JSONPath expression starts with `$`, which refers to the root of the document.

$          — root element
$.key      — property named "key" on the root object
$.a.b.c    — nested property access
$.arr[0]   — first element of "arr" array
$.arr[-1]  — last element (negative index)
$.arr[*]   — all elements of "arr"
$.*        — all properties of root object

Recursive Descent (..)

The `..` operator finds a key at any depth — you do not need to know the nesting structure.

$..name       — all "name" values anywhere in the document
$..book[*]    — all elements of any "book" array

Array Slices

JSONPath supports Python-style array slicing:

$.arr[0:3]    — elements at index 0, 1, 2
$.arr[::2]    — every second element
$.arr[-2:]    — last two elements

Filter Expressions

Filters select array elements that match a condition:

$.books[?(@.price < 30)]          — books cheaper than $30
$.items[?(@.status == "active")]  — items with status "active"
$.users[?(@.age >= 18)]           — users aged 18 or older

The `@` refers to the current element being tested. Supported operators: ==, !=, <, <=, >, >=.

Practical Examples

Given:

json
{
  "store": {
    "book": [
      { "title": "Clean Code",  "author": "Martin", "price": 29.99 },
      { "title": "Refactoring", "author": "Fowler", "price": 34.99 }
    ]
  }
}

| Expression | Result | |---|---| | `$.store.book[*].title` | ["Clean Code", "Refactoring"] | | `$..author` | ["Martin", "Fowler"] | | `$.store.book[0].price` | 29.99 | | `$.store.book[?(@.price < 30)].title` | ["Clean Code"] |

Testing JSONPath Expressions

Use JSONKit's JSONPath Tester to evaluate any expression against your JSON interactively. Paste the JSON, type the expression, and see every match with its full path — no libraries, no CLI, runs entirely in your browser.

Try JSONPath Tester

Test JSONPath expressions against live JSON and see matching results.