Skip to content

JSONPath cheat sheet with examples

Every JSONPath selector and filter you'll need on one page, each with an example and its result, following the RFC 9535 standard.

Guide5 min readUpdated

JSONPath is a query language for picking values out of a JSON document, the way XPath does for XML. It's used in API testing tools, Kubernetes (kubectl -o jsonpath), databases and many libraries, and since 2024 it's standardised as RFC 9535. Every example below uses this document and was checked in the JSON Query Selector, where you can paste it and try them yourself.

{
  "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": 399 }
  }
}
The sample document (the classic bookstore example)

Basic selectors

ExpressionMeaningResult
$The root of the documentthe whole document
$.store.bicycle.colorA child by name (dot notation)"red"
$['store']['bicycle']A child by name (bracket notation, for keys with spaces or symbols){ "color": "red", "price": 399 }
$.store.*Wildcard: every childthe book array and the bicycle object
$..authorRecursive descent: author at any depth"Nigel Rees", "Evelyn Waugh", "Herman Melville", "J. R. R. Tolkien"
$..priceEvery price anywhere8.95, 12.99, 8.99, 22.99, 399

Arrays: indexes and slices

ExpressionMeaningResult
$.store.book[0].titleThe first item (indexes start at 0)"Sayings of the Century"
$.store.book[-1].titleThe last item"The Lord of the Rings"
$.store.book[0,2].titleSeveral indexes"Sayings of the Century", "Moby Dick"
$.store.book[0:2].titleA slice: from index 0 up to (not including) 2"Sayings of the Century", "Sword of Honour"
$.store.book[*].authorEvery itemall four authors

Filters

ExpressionMeaningResult
$.store.book[?@.price < 10].titleItems where a comparison is true (@ is the current item)"Sayings of the Century", "Moby Dick"
$.store.book[?@.isbn].titleItems that have a key"Moby Dick", "The Lord of the Rings"
$.store.book[?@.category == 'fiction' && @.price > 10].titleCombine conditions with && and ||"Sword of Honour", "The Lord of the Rings"
$..book[?length(@.title) > 15].titlelength() of a string, array or object"Sayings of the Century", "The Lord of the Rings"
$.store.book[?count(@.*) > 4].titlecount(): the number of matches of a query (here, keys per book)"Moby Dick", "The Lord of the Rings"
$.store.book[?value(@.price) > 20].titlevalue(): the single value a query matches"The Lord of the Rings"
$.store.book[?match(@.author, '.*Tolkien')].titlematch(): the whole value matches a regular expression"The Lord of the Rings"
$.store.book[?search(@.author, 'Mel')].titlesearch(): the value contains a match"Moby Dick"

Filter operators

  • Comparison: == != < <= > >=
  • Logic: && (and), || (or), ! (not), and parentheses for grouping
  • Strings use single or double quotes: @.category == 'fiction'
  • $ inside a filter refers to the document root, so values can be compared with other parts of the document
  • Functions from RFC 9535: length(), count(), match(), search() and value()

Tips

  • A query always returns a list of matches, even when only one value matches, and an empty list when none do.
  • Use bracket notation for keys that aren't simple names: $['first name'], $['user-id'].
  • Don't know the path to a value? Search for it with JSON Deep Search, which shows the full path of every match, or click it in the Tree Viewer.

Frequently asked questions

Is JSONPath a standard?

Yes, since February 2024: RFC 9535 standardised JSONPath. Before that, implementations followed Stefan Goessner's 2007 article and differed in details, especially filters, so older libraries may not support every example here.

What's the difference between JSONPath and jq?

JSONPath only selects values from a document. jq is a full language that can also transform, compute and reshape JSON. JSONPath is common inside other tools (Kubernetes, API testing, databases); jq is a command-line tool.

Do I need ( ) around filter expressions?

RFC 9535 writes filters as [?@.price < 10]. The older [?(@.price < 10)] form with parentheses still works in most implementations, including the JSON Toolkit Query tool.

Tools used in this guide

More guides