Tutorial · 6 min read

JSONPath Tutorial: Query Nested JSON with Examples

JSONPath is to JSON what XPath is to XML — a query language for extracting specific data from complex structures. Use a JSONPath tester to experiment with expressions in real-time.

1. Sample JSON Data

All examples in this tutorial use this JSON document:

{
  "store": {
    "name": "JSONXX Books",
    "books": [
      {"title": "JSON for Beginners", "price": 29, "tags": ["json", "beginner"]},
      {"title": "Advanced JSON", "price": 49, "tags": ["json", "advanced"]},
      {"title": "Web APIs 101", "price": 39, "tags": ["api", "rest"]}
    ],
    "location": {"city": "Beijing", "country": "China"}
  }
}

Copy this and paste it into the JSONPath tester to follow along with each example.

2. Dot Notation — Accessing Specific Fields

Use dots to chain keys from root to target:

ExpressionResult
$.store.name"JSONXX Books"
$.store.books[0].title"JSON for Beginners"
$.store.location.city"Beijing"

Array indices start at 0. $.store.books[0] gets the first book object. Chain further with .title to get a specific field.

3. Wildcards — Matching Multiple Elements

Use [*] or .* to match all elements without knowing specific keys or indices:

ExpressionResult
$.store.books[*].titleAll 3 book titles
$.store.*All properties of store

Wildcards are essential when you don't know the array length or object keys in advance.

4. Filters — Conditional Queries

Use [?()] to select elements matching a condition:

ExpressionResult
$.store.books[?(@.price > 30)]Books with price > 30
$.store.books[?(@.price < 40 && @.price > 25)]Price between 25-40
$.store.books[?(@.tags.contains('json'))]Books tagged "json"

Supported operators: ==, !=, >, <, >=, <=, contains. Combine multiple conditions with && and ||.

5. Recursive Descent — Find Anywhere

The double-dot .. operator searches at any nesting depth:

ExpressionResult
$..titleAll "title" values at any depth
$..city"Beijing" (nested in location)
$..priceAll price values: 29, 49, 39

Pro tip: Recursive descent is powerful but expensive on large documents. Use it when you know a property exists but don't know exactly where. For queries that need extraction into other formats, use JSON to CSV after obtaining results with JSONPath.

Try the Free JSONPath Tester

Paste JSON, enter JSONPath expressions, and see results in real-time. Supports all operators.

Test JSONPath Now →

Best Practices for JSONPath Queries

Frequently Asked Questions

How to test JSONPath expressions online?

Paste JSON into a JSONPath tester, enter your expression in the query bar, and see matching results update in real-time.

How to filter JSON arrays with JSONPath?

Use [?()] syntax: $.users[?(@.age > 30)]. Supports ==, !=, >, <, >=, <=, and contains operators.

What is the difference between . and .. in JSONPath?

Single dot . accesses direct children. Double dot .. performs recursive descent — it searches all nested levels for matching property names.

Can JSONPath extract data for CSV export?

Yes. Once you've identified the data using JSONPath, copy the result and paste it into JSON to CSV for spreadsheet export.

Is my JSON data safe in the JSONPath tester?

Yes. All evaluation is 100% browser-based. Your JSON never leaves your computer. No server uploads, no storage, no tracking.

Looking for more guides? See the full JSONXX How To index.