JSONPath Cheatsheet

JSONPath is a query language for picking values out of a JSON document — like XPath for JSON. Here's the syntax with worked examples. Run any of them live in the JSONPath tester.

Open the JSONPath tester →

Sample document

The examples below run against this JSON:

{
  "store": {
    "book": [
      { "title": "Sayings of the Century", "price": 8.95 },
      { "title": "Moby Dick", "price": 12.99 },
      { "title": "The Lord of the Rings", "price": 22.99 }
    ],
    "bicycle": { "color": "red", "price": 19.95 }
  }
}

Operators

SyntaxMeaning
$The root object
.key or ['key']Child by name
..keyRecursive descent — find key at any depth
*Wildcard — all children
[n]Array element by index (0-based)
[start:end]Array slice (end exclusive)
[?(@.x > 1)]Filter — elements where the expression is true (@ = current item)
[a,b]Union — multiple names or indices

Examples

JSONPathSelects
$.store.book[*].titleAll three book titles
$..priceEvery price: 8.95, 12.99, 22.99, 19.95
$.store.book[0]The first book object
$.store.book[-1].title"The Lord of the Rings" (last book)
$.store.book[0:2]The first two books
$.store.book[?(@.price < 10)]Books cheaper than 10 (the first book)
$..book[?(@.price > 20)].titleTitles of books over 20
$.store.*Everything in the store (the book array and the bicycle)
$..*Every value in the document, recursively

Note: a few details (e.g. negative indices, the exact filter grammar) vary between JSONPath implementations. Paste your document into the tester to confirm what a given expression returns for your data.

Try these in the JSONPath tester →