Skip to content
jsonblocks

JSONPath syntax cheat sheet

JSONPath addresses values inside a JSON document the way file paths address files: $.store.book[0].title reads the title of the first book. This cheat sheet covers the syntax you will use daily, with runnable examples.

Every expression starts at the root $, then walks down with dots for object keys and brackets for array indices. That covers most real usage; wildcards, slices, and filters handle the rest.

The example document

json
{
  "store": {
    "book": [
      { "title": "A", "price": 8.95 },
      { "title": "B", "price": 12.99 }
    ],
    "open": true
  }
}

Everyday expressions

Core JSONPath syntax with results against the example.
ExpressionSelectsResult
$The rootWhole document
$.store.openObject keytrue
$.store.book[0]First array item{ title: A, … }
$.store.book[0].titleNested key"A"
$.store.book[-1].titleLast array item"B"
$.store.book[*].titleWildcard: all titles["A", "B"]
$..priceRecursive descent[8.95, 12.99]
$.store.book[0:2].titleSlice of items["A", "B"]

Filters

Filters select array items by condition. $.store.book[?(@.price < 10)].title returns "A" only. The @ symbol means the current item, and most implementations support comparison and existence checks.

json
$.store.book[?(@.price < 10)].title   // "A"
$.store.book[?(@.title)].price      // [8.95, 12.99]

Keys with special characters

Dot notation only suits simple keys. For keys with dots, spaces, or dashes, use bracket quotes: $['weird.key'] or $["kebab-key"]. When a path misbehaves, the key spelling is the first suspect.

JSONPath vs jq vs JSON Pointer

  • JSONPath ($.a.b) is the query language of config tools, Kubernetes, and REST test suites.
  • jq (.a.b) is the terminal counterpart: same idea, different root symbol, far more transform power.
  • JSON Pointer (/a/b) is the RFC standard for patches and schemas - slashes instead of dots.

Frequently asked questions

What does $ mean in JSONPath?

The root of the document. Every JSONPath expression starts at $ and walks down, so $.store.book[0] means: from the root, key store, key book, index 0.

How do I select all items in an array?

Use the wildcard: $.store.book[*].title returns every title. For a range, use a slice like [0:2]. For matching items, use a filter like [?(@.price < 10)].

Why does my path return nothing?

Usual causes: a misspelled key, 1-based indexing instead of 0-based, or addressing an object where the document has an array. Paste the document into the path finder to browse the real paths.