JSONPath Cheat Sheet

Every JSONPath operator, filter expression, and selector in one place. Includes a sample document, 15+ practical examples with results, and jq equivalents.

JSONTech TeamMarch 10, 20256 min read

Sample JSON Document

All examples below use this bookstore dataset:

{
  "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.99
    }
  }
}

Core Operators

OperatorDescriptionExampleResult
$Root object$The entire document
.Child operator (dot notation)$.store.bicycle.color"red"
..Recursive descent (deep scan)$..price[8.95, 12.99, 8.99, 22.99, 399.99]
*Wildcard — all children$.store.book[*].authorAll 4 author names
[]Bracket notation / subscript$.store.book[0]First book object
[,]Union — multiple indices$.store.book[0,2]1st and 3rd books
[start:end]Array slice$.store.book[0:2]First 2 books (index 0, 1)
[start:end:step]Array slice with step$.store.book[::2]Every other book (index 0, 2)
[?()]Filter expression$.store.book[?(@.price < 10)]Books cheaper than $10
@Current node (used in filters)@.pricePrice of current element
.lengthLength of array or string$.store.book.length4

Filter Operators

Used inside [?()] filter expressions with @ referencing the current node:

OperatorMeaningExample
==Equals[?(@.category == "fiction")]
!=Not equals[?(@.category != "reference")]
<Less than[?(@.price < 10)]
>Greater than[?(@.price > 20)]
<=Less than or equal[?(@.price <= 8.99)]
>=Greater than or equal[?(@.price >= 12.99)]
=~Regex match[?(@.author =~ /.*Tolkien/i)]
inValue in list[?(@.category in ["fiction", "reference"])]
ninValue not in list[?(@.category nin ["reference"])]
&&Logical AND[?(@.price < 10 && @.category == "fiction")]
||Logical OR[?(@.price < 10 || @.price > 20)]

Practical Examples

ExpressionDescriptionResult
$.store.book[*].authorAll authors["Nigel Rees", "Evelyn Waugh", "Herman Melville", "J. R. R. Tolkien"]
$..authorAll authors (recursive)Same as above
$.store.*All things in the storeBook array + bicycle object
$..priceAll prices everywhere[8.95, 12.99, 8.99, 22.99, 399.99]
$.store.book[2]Third book (zero-indexed)Moby Dick object
$.store.book[-1]Last bookThe Lord of the Rings object
$.store.book[0:2]First two booksSayings of the Century, Sword of Honour
$.store.book[?(@.isbn)]Books that have an ISBNMoby Dick, The Lord of the Rings
$.store.book[?(!@.isbn)]Books without an ISBNSayings of the Century, Sword of Honour
$.store.book[?(@.price < 10)]Books cheaper than $10Sayings of the Century, Moby Dick
$.store.book[?(@.price > 20)]Books over $20The Lord of the Rings
$.store.book[?(@.category == "fiction")]Fiction books onlySword of Honour, Moby Dick, The Lord of the Rings
$.store.book[?(@.author =~ /.*Melville/)]Author matching regexMoby Dick
$..book[?(@.price < 10 && @.isbn)]Cheap books with ISBNMoby Dick
$.store.book[*].titleAll book titles["Sayings of the Century", "Sword of Honour", "Moby Dick", "The Lord of the Rings"]
$.store.book.lengthNumber of books4

JSONPath vs jq

TaskJSONPathjq Equivalent
Root$.
Child access$.store.book.store.book
Array index$.store.book[0].store.book[0]
All elements$.store.book[*].store.book[]
Recursive$..price.. | .price? // empty
Filter by value$.store.book[?(@.price < 10)].store.book[] | select(.price < 10)
Field existence$.store.book[?(@.isbn)].store.book[] | select(has("isbn"))
Slice$.store.book[0:2].store.book[:2]
Multiple fields$..book[*]['title','price'].store.book[] | {title, price}

Common Mistakes

MistakeProblemFix
store.book[0]Missing root $$.store.book[0]
$.store.book[?(@.price = 10)]Single = (assignment) instead of ==$.store.book[?(@.price == 10)]
$.store.book[1:3:0]Step of 0 is invalid$.store.book[1:3] or [1:3:1]
$..book..authorDouble recursive can produce duplicates$..book[*].author or $..author
Unquoted string in filter[?(@.cat == fiction)] fails[?(@.cat == "fiction")]
Forgetting @ in filters[?(price < 10)] fails[?(@.price < 10)]

Test your JSONPath expressions live: Paste your JSON and try any expression in our JSONPath Tester — see matching results instantly.

Related Tools