JSONPath Cheat Sheet: Queries with Examples

Updated · 6 min read · MetaSol Technologies

JSONPath is a small query language for picking values out of JSON, the way a file path picks a file out of folders. API testing tools, log processors, databases and automation platforms all use it. This cheat sheet uses one example document throughout; paste it into the JSON Path Explorer to try each query.

{
  "store": {
    "book": [
      { "title": "Sayings of the Century", "author": "N. Rees", "price": 8.95 },
      { "title": "Sword of Honour", "author": "E. Waugh", "price": 12.99 },
      { "title": "Moby Dick", "author": "H. Melville", "price": 8.99, "isbn": "0-553-21311-3" }
    ],
    "bicycle": { "color": "red", "price": 19.95 }
  }
}

The basics

Expression Meaning Result
$ The whole document (root) everything
$.store.bicycle.color Child by name "red"
$['store']['bicycle'] Bracket notation (needed for names with spaces or dots) the bicycle object
$.store.book[0].title First array item (counting from 0) "Sayings of the Century"
$.store.book[-1].title Last array item "Moby Dick"

Many values at once

Expression Meaning Result
$.store.book[*].author Every item in an array all three authors
$.store.* Every child of an object the book array and the bicycle
$..price Recursive descent: price at any depth four prices
$.store.book[0,2] A union of indexes first and third book
$.store.book[0:2] A slice: index 0 up to (not including) 2 first two books

Filters

Filters keep the items for which a condition is true. @ means "the current item".

Expression Result
$.store.book[?(@.price < 10)].title titles of books under 10
$..book[?(@.isbn)] books that have an isbn field
$..book[?(@.author == 'E. Waugh')] books by a specific author
$..book[?(@.price > 8 && @.price < 10)] combined conditions

Common mistakes

  • Forgetting $. Most implementations require queries to start at the root.
  • Counting from 1. Arrays start at index 0.
  • Expecting one value. $..price returns a list, even if only one value matches.
  • Implementation differences. Filters and edge cases vary between libraries. RFC 9535 (2024) standardised JSONPath, but older tools predate it, so test queries against the library your code uses.

JSONPath vs JSON Pointer

JSON Pointer (/store/book/0/title) addresses exactly one value and has no wildcards or filters. Use JSONPath to search, and JSON Pointer when you need one precise location, as in JSON Patch.