WebTool

The Complete JSONPath Syntax Guide: From Basics to Real-World Use

WebTool Team · Published 2026-09-01 · JSON / JSONPath / API Debugging

JSONPath is a query language for extracting data from JSON documents — it plays the same role for JSON that XPath plays for XML. This post covers all the commonly used syntax in about 10 minutes, with real API debugging examples. Once you're done reading, you can practice right away in our JSONPath tool.

Basic Syntax

Syntax Meaning Example
$ Root node (every expression must start with it) $
.key Child key $.store.name
['key'] Child key (for key names with special characters) $['user-name']
[0] Array index (zero-based) $.users[0]
[*] All elements of an array/object $.users[*].name
..key Recursive descent: find the key at any depth $..price

Filters and Slices

Inside a filter expression [?(...)], @ refers to the current element:

$.store.book[?(@.price < 10)]        // books priced under 10
$.users[?(@.age >= 18)].name        // names of adult users

Array slicing works just like Python:

$.items[0:3]    // first 3 items (index 3 excluded)
$.items[-1]     // last item

Hands-On: Debugging a Paginated API

Suppose the API returns:

{
  "code": 0,
  "data": {
    "list": [
      { "id": 101, "title": "First article", "author": { "name": "Alice" } },
      { "id": 102, "title": "Second article", "author": { "name": "Bob" } }
    ],
    "total": 57
  }
}

Common extraction paths:

Goal Expression
All article titles $.data.list[*].title
All author names $..name
Author of the first article $.data.list[0].author.name
Total count $.data.total

Common Mistakes

  1. Forgetting the leading $data.list is invalid; it should be $.data.list.
  2. Key names containing dots or dashes — use ['key.name'] instead of .key.name.
  3. Using $ inside a filter — inside a filter expression, @ refers to the current element, not $.

Last updated: 2026-09-01