AllJSONTools

Free JSON Developer Tools

JSONPath Cheatsheet: Query JSON Like a Pro

2026-02-20 · 7 min read · By AllJSONTools

JSONPath
Query
Data
Having JSON issues?

Paste broken JSON and fix it instantly with AI — plain-English explanations included.

Fix JSON with AI

What is JSONPath?

JSONPath is a query language for JSON data, much like XPath is for XML. It provides a concise syntax for selecting and extracting elements from a JSON document. Originally proposed by Stefan Goessner in 2007, JSONPath has become an indispensable tool for developers working with structured data across a wide range of applications.

You will find JSONPath invaluable whenever you need to query REST API responses, filter large JSON datasets, write assertions in automated API tests, extract configuration values from deeply nested JSON files, or transform data in ETL pipelines. Rather than writing verbose loops and conditionals, a single JSONPath expression can pinpoint exactly the data you need.

If you are already familiar with dot-notation property access in JavaScript, you will find JSONPath intuitive. The key difference is that JSONPath adds powerful operators for recursive search, array slicing, and conditional filtering that plain dot notation cannot offer.

Quick Reference

The table below summarizes the most commonly used JSONPath expressions. Every example assumes the sample JSON data shown later in this article.

ExpressionDescriptionExample Result
$The root object / elementThe entire JSON document
$.store.bookChild operator (dot notation)The array of all books
$..authorRecursive descent — finds all authors["Nigel Rees", "Evelyn Waugh", "Herman Melville", "J. R. R. Tolkien"]
$.store.book[0]Array index (first element)The first book object
$.store.book[*]Wildcard — all elements in the arrayAll four book objects
$.store.book[0:2]Array slice (index 0 up to, but not including, 2)First two book objects
$.store.book[?(@.price<10)]Filter expression — books cheaper than 10Books priced below 10
$.store.book[-1:]Negative index — the last elementThe last book object

Sample JSON Data

All examples in this cheatsheet reference the following JSON document. This is the classic “store” example used in most JSONPath tutorials. Feel free to paste it into our JSONPath Query Tool and experiment with the expressions yourself.

json
{
  "store": {
    "book": [
      {
        "category": "reference",
        "author": "Nigel Rees",
        "title": "Sayings of the Century",
        "price": 8.95
      },
      {
        "category": "fiction",
        "author": "Evelyn Waugh",
        "title": "Sword of Honour",
        "price": 12.99
      },
      {
        "category": "fiction",
        "author": "Herman Melville",
        "title": "Moby Dick",
        "isbn": "0-553-21311-3",
        "price": 8.99
      },
      {
        "category": "fiction",
        "author": "J. R. R. Tolkien",
        "title": "The Lord of the Rings",
        "isbn": "0-395-19395-8",
        "price": 22.99
      }
    ],
    "bicycle": {
      "color": "red",
      "price": 19.95
    }
  }
}

Basic Selectors

Basic selectors form the foundation of every JSONPath expression. Master these three concepts and you will be able to navigate any JSON structure with confidence.

Root Selector — $

Every JSONPath expression starts with the dollar sign $, which represents the root of the JSON document. Used on its own, it returns the entire document.

json
// Query
$

// Result: the entire JSON document
{
  "store": {
    "book": [ ... ],
    "bicycle": { ... }
  }
}

Child Selector — .field and ['field']

The child selector accesses a property of the current object. You can use dot notation (.field) or bracket notation (['field']). Bracket notation is required when the property name contains spaces, special characters, or starts with a digit.

json
// Dot notation
$.store.bicycle.color

// Result
"red"
json
// Bracket notation (equivalent)
$['store']['bicycle']['color']

// Result
"red"

You can chain child selectors to drill into deeply nested structures. For example, $.store.book returns the entire array of books, while $.store.bicycle.price returns 19.95.

json
// Query
$.store.bicycle

// Result
{
  "color": "red",
  "price": 19.95
}

Recursive Descent — ..

The recursive descent operator .. searches the entire JSON tree for matching property names, regardless of depth. This is one of JSONPath’s most powerful features, allowing you to extract all occurrences of a key without knowing its exact location.

json
// Query — find every "author" in the document
$..author

// Result
[
  "Nigel Rees",
  "Evelyn Waugh",
  "Herman Melville",
  "J. R. R. Tolkien"
]
json
// Query — find every "price" in the document (books + bicycle)
$..price

// Result
[8.95, 12.99, 8.99, 22.99, 19.95]

Notice that $..price returns prices from both the books and the bicycle because the recursive descent operator traverses every branch of the tree.

Array Operations

JSON data frequently contains arrays, and JSONPath provides rich syntax for accessing individual elements, ranges, and entire collections. These array operations work similarly to Python’s list slicing, making them familiar to many developers.

Index Access — [0] and [-1]

Use a zero-based index inside square brackets to select a specific array element. Negative indices count from the end of the array, so [-1] always selects the last element.

json
// Query — first book
$.store.book[0]

// Result
{
  "category": "reference",
  "author": "Nigel Rees",
  "title": "Sayings of the Century",
  "price": 8.95
}
json
// Query — last book (negative index)
$.store.book[-1]

// Result
{
  "category": "fiction",
  "author": "J. R. R. Tolkien",
  "title": "The Lord of the Rings",
  "isbn": "0-395-19395-8",
  "price": 22.99
}

Array Slicing — [start:end]

Slicing lets you select a range of elements from an array. The syntax is [start:end], where start is inclusive and end is exclusive. Either bound can be omitted: [1:] means “from index 1 to the end,” and [:2] means “from the start up to (but not including) index 2.”

json
// Query — first three books (indices 0, 1, 2)
$.store.book[0:3]

// Result
[
  {
    "category": "reference",
    "author": "Nigel Rees",
    "title": "Sayings of the Century",
    "price": 8.95
  },
  {
    "category": "fiction",
    "author": "Evelyn Waugh",
    "title": "Sword of Honour",
    "price": 12.99
  },
  {
    "category": "fiction",
    "author": "Herman Melville",
    "title": "Moby Dick",
    "isbn": "0-553-21311-3",
    "price": 8.99
  }
]
json
// Query — from the second book onward
$.store.book[1:]

// Result
[
  {
    "category": "fiction",
    "author": "Evelyn Waugh",
    "title": "Sword of Honour",
    "price": 12.99
  },
  {
    "category": "fiction",
    "author": "Herman Melville",
    "title": "Moby Dick",
    "isbn": "0-553-21311-3",
    "price": 8.99
  },
  {
    "category": "fiction",
    "author": "J. R. R. Tolkien",
    "title": "The Lord of the Rings",
    "isbn": "0-395-19395-8",
    "price": 22.99
  }
]
json
// Query — first two books
$.store.book[:2]

// Result
[
  {
    "category": "reference",
    "author": "Nigel Rees",
    "title": "Sayings of the Century",
    "price": 8.95
  },
  {
    "category": "fiction",
    "author": "Evelyn Waugh",
    "title": "Sword of Honour",
    "price": 12.99
  }
]

Wildcard — [*]

The wildcard operator [*] selects all elements in an array or all values in an object. When combined with a child selector, it becomes a powerful way to project a single field from every element in an array.

json
// Query — all books (equivalent to $.store.book)
$.store.book[*]

// Result: all four book objects
json
// Query — all titles from all books
$.store.book[*].title

// Result
[
  "Sayings of the Century",
  "Sword of Honour",
  "Moby Dick",
  "The Lord of the Rings"
]

You can also use the wildcard on objects. For instance, $.store.* would return both the book array and the bicycle object.

Filter Expressions

Filter expressions let you select elements based on conditions. They use the syntax [?(<expression>)], where @ refers to the current element being evaluated. Filters are what make JSONPath truly powerful for real-world data extraction tasks.

Comparison Operators

JSONPath supports the standard comparison operators: == (equal), != (not equal), < (less than), > (greater than), <= (less than or equal), and >= (greater than or equal).

json
// Query — books cheaper than 10
$.store.book[?(@.price < 10)]

// Result
[
  {
    "category": "reference",
    "author": "Nigel Rees",
    "title": "Sayings of the Century",
    "price": 8.95
  },
  {
    "category": "fiction",
    "author": "Herman Melville",
    "title": "Moby Dick",
    "isbn": "0-553-21311-3",
    "price": 8.99
  }
]
json
// Query — books that cost exactly 12.99
$.store.book[?(@.price == 12.99)]

// Result
[
  {
    "category": "fiction",
    "author": "Evelyn Waugh",
    "title": "Sword of Honour",
    "price": 12.99
  }
]
json
// Query — books in the "fiction" category
$.store.book[?(@.category == "fiction")]

// Result
[
  {
    "category": "fiction",
    "author": "Evelyn Waugh",
    "title": "Sword of Honour",
    "price": 12.99
  },
  {
    "category": "fiction",
    "author": "Herman Melville",
    "title": "Moby Dick",
    "isbn": "0-553-21311-3",
    "price": 8.99
  },
  {
    "category": "fiction",
    "author": "J. R. R. Tolkien",
    "title": "The Lord of the Rings",
    "isbn": "0-395-19395-8",
    "price": 22.99
  }
]

Logical Operators

Combine multiple conditions with && (logical AND) and || (logical OR) to build more precise filters. This is essential when your data selection criteria involve more than one field or threshold.

json
// Query — fiction books cheaper than 15
$.store.book[?(@.category == "fiction" && @.price < 15)]

// Result
[
  {
    "category": "fiction",
    "author": "Evelyn Waugh",
    "title": "Sword of Honour",
    "price": 12.99
  },
  {
    "category": "fiction",
    "author": "Herman Melville",
    "title": "Moby Dick",
    "isbn": "0-553-21311-3",
    "price": 8.99
  }
]
json
// Query — books that are either "reference" or priced over 20
$.store.book[?(@.category == "reference" || @.price > 20)]

// Result
[
  {
    "category": "reference",
    "author": "Nigel Rees",
    "title": "Sayings of the Century",
    "price": 8.95
  },
  {
    "category": "fiction",
    "author": "J. R. R. Tolkien",
    "title": "The Lord of the Rings",
    "isbn": "0-395-19395-8",
    "price": 22.99
  }
]

Existence Check

You can check whether a property exists on an element by simply referencing it in a filter without a comparison operator. The expression ?(@.isbn) evaluates to true for any element that has an isbn property, regardless of its value.

json
// Query — books that have an ISBN
$.store.book[?(@.isbn)]

// Result
[
  {
    "category": "fiction",
    "author": "Herman Melville",
    "title": "Moby Dick",
    "isbn": "0-553-21311-3",
    "price": 8.99
  },
  {
    "category": "fiction",
    "author": "J. R. R. Tolkien",
    "title": "The Lord of the Rings",
    "isbn": "0-395-19395-8",
    "price": 22.99
  }
]

This is extremely useful when working with API responses that include optional fields. Instead of guarding against missing properties in your application code, you can let JSONPath filter them out at the query level.

Common Patterns

The following patterns come up repeatedly in day-to-day development. Keep them in your toolbox and you will be able to tackle most JSON querying tasks in seconds.

Get All Values of a Specific Key

The recursive descent operator .. is the fastest way to collect every occurrence of a particular key, no matter how deeply nested it is in the document. This pattern is ideal for aggregating values like prices, IDs, or timestamps scattered across a complex response.

json
// Query — every price in the document
$..price

// Result
[8.95, 12.99, 8.99, 22.99, 19.95]

Because $..price traverses the entire tree, it returns the bicycle price (19.95) alongside the book prices. If you want only the book prices, be more specific: $.store.book[*].price.

Find Items Matching a Condition

Combining array access with filter expressions lets you search for items that meet specific criteria. This is analogous to a SQL WHERE clause and is one of the most frequently used patterns in API testing and data processing.

json
// Query — find all books priced under 10
$.store.book[?(@.price < 10)]

// Result
[
  {
    "category": "reference",
    "author": "Nigel Rees",
    "title": "Sayings of the Century",
    "price": 8.95
  },
  {
    "category": "fiction",
    "author": "Herman Melville",
    "title": "Moby Dick",
    "isbn": "0-553-21311-3",
    "price": 8.99
  }
]

You can filter on any field. For example, to find all books by a particular author you would write $.store.book[?(@.author == "Herman Melville")].

Select Specific Fields from Arrays

When you only need one property from each element of an array, combine the wildcard [*] with a child selector. This is the JSONPath equivalent of a SELECT column FROM table query and is perfect for building dropdown lists, search indices, or summary views.

json
// Query — all book titles
$.store.book[*].title

// Result
[
  "Sayings of the Century",
  "Sword of Honour",
  "Moby Dick",
  "The Lord of the Rings"
]
json
// Query — all book categories
$.store.book[*].category

// Result
[
  "reference",
  "fiction",
  "fiction",
  "fiction"
]

You can also combine this pattern with filters. For instance, $.store.book[?(@.price < 10)].title returns only the titles of books that cost less than 10: ["Sayings of the Century", "Moby Dick"].

Try It Yourself

The best way to learn JSONPath is through hands-on experimentation. Copy the sample JSON above and try each expression in a live environment. AllJSONTools provides free, browser-based tools that make this easy:

  • JSONPath Query Tool — Paste your JSON, type a JSONPath expression, and instantly see the matching results. Supports all the operators covered in this cheatsheet, including filters and recursive descent.

  • JSON Tree Viewer — Visualize the structure of your JSON document as a collapsible tree. This can help you understand the nesting hierarchy before writing your JSONPath expressions.

Start with simple selectors like $.store.book[0].title and gradually work your way up to filters and recursive queries. Once you are comfortable, try combining multiple techniques — for example, $.store.book[?(@.price < 15)].author to get the authors of all affordable books.

If you need to validate or format your JSON before querying it, check out our JSON Formatter for quick prettification and syntax validation.

Having JSON issues?

Paste broken JSON and fix it instantly with AI — plain-English explanations included.

Fix JSON with AI