JSONPath cheat sheet: expressions that work

25 NOVEMBER 2026 · 9 MIN READ

JSONPath has no single specification, so a cheat sheet is only worth as much as the engine behind it. The query tool runs JSONPath Plus with every answer wrapped in an array — these expressions and these failures are what that produces.

There are at least four dialects of JSONPath in circulation, and they disagree about filters, negative indexes and whether a missing key is an error. Rather than translate the RFC drafts, this page lists what the query tool actually returns: JSONPath Plus, called with wrap: true, so the result is always a list even when one node matched. Every expression below was run against the document at the bottom of this section — the same one the page loads — and the failures are listed with the rest, because they are the part that costs an afternoon.

The sample document
{
  "project": "Aurora API",
  "owner": { "name": "Mira Chen", "email": "mira@example.dev",
            "team": ["platform", "developer-experience"] },
  "services": [
    { "name": "gateway",  "port": 8080, "healthy": true },
    { "name": "indexer",  "port": 8081, "healthy": false },
    { "name": "renderer", "port": 8082, "healthy": true }
  ]
}

Navigation

ExpressionReturns
$the whole document, inside an array
$.project["Aurora API"]
$['owner']['name']bracket form, needed for keys with spaces or dots
$.services[0].name["gateway"]
$.services[*].nameall three names
$.services.*each service object
$..namethe owner name plus every service name — recursive descent matches the key at any depth
$..services..namedescent can be chained; here it lands back on the same three
$..emailevery value stored under email, however deeply buried
$..*every value in the document — useful, rarely readable
$.services.length[3]
$..['name','email']a union of two keys applied across the tree

Filters

A filter is ?( expression ) and the expression is real JavaScript with @ bound to the candidate. That is the most useful part of the language and the part most people write wrong, because they reach for the textbook operators instead of the methods the language already has.

ExpressionReturns
$.services[?(@.healthy)].nametruthiness — gateway, renderer
$.services[?(@.healthy === true)].namethe same, written explicitly; use ===, since == in this dialect is a comparison too
$.services[?(@.port > 8080)].nameindexer, renderer
$.services[?(@.port >= 8081 && @.healthy)].namerenderer only — && and || both work
$.services[?(@.port % 2 === 0)].namearithmetic in the comparison is fine
$.services[?(@.name.includes('i'))].namesubstring — indexer
$.services[?(@.name.startsWith('g'))].nameprefix
$.services[?(@.name.match(/^i/))].nameregex against the field
$.services[?(/^i/.test(@.name))].namethe same regex, written the other way round
$.owner.team[?(@ === 'platform')]for a scalar array, @ is the item itself
$.owner.team[?(@.length > 8)]length works on a string too
$.services[?(typeof @.name === 'string')].nameguards against records missing the field

Slices and unions

  • ▸$.services[0,2].name — a comma-separated list of indexes.
  • ▸$.services[1:].name and $.services[:1].name — open-ended slices behave as they do in JavaScript.
  • ▸$.services[-2:].name — a negative index inside a slice is the supported way to count from the end.
  • ▸$..['name','email'] — a key union, which can be combined with descent to pull the same fields out of every record.

Expressions that return nothing, or throw

WrittenWhat happensWrite instead
$.services[-1].namean empty result — a bare negative index is not part of this dialect$.services[-1:].name
$.services[#-1].namerejected: Unexpected #. The # counter is from an older grammar$.services[-1:].name
$.services[?@.healthy].namean empty result; the unparenthesised filter does not parse into anything$.services[?(@.healthy)].name
$.services[?(@.name)].lengthempty — length attaches to an array path, not to a filter resultcount the rows after the query
$..[('name','email')]throws: the parenthesised union is a different dialect$..['name','email']
$.services[?(@.name =~ /^i/)]throws: Invalid left-hand side in assignment — =~ is not this engine's operator$.services[?(@.name.match(/^i/))]
$.services[?(@.name === search(/^i/, 'x'))]search is not defined in the sandboxed expression scopeuse .match()
$.services[*][?(@.healthy)]empty — a wildcard followed by a filter does not chain here$.services[?(@.healthy)]
$.missing.anythingan empty result, never an errornothing — that silence is the point
The query module with the expression $.services[-1].name and the result pane showing only the comment No matches
A bare negative index is accepted and answers with nothing
The query module with the expression $.services[-1:].name and the result pane returning the string renderer
The slice form resolves the same last element

Why a rejected expression can still show results

The query module keeps a second, smaller engine for the case where the primary one cannot load. When an expression throws, evaluation falls through to that subset, which implements dotted paths, [0], [*], ..key and single-comparison filters — and, confusingly, accepts a bare negative index and the quoted =~ form the primary engine rejects. So an answer can come from either place, and the two are not identical. The signal is the browser console: it records which expression was refused. If a filter “works” but behaves oddly, assume it was answered by the fallback and rewrite it in the plain forms listed above — dotted paths, comparisons and .includes() are the subset both engines agree on.

Recipes that cover most real work

  1. 01 Every value of a key, anywhere: $..email. This is the single most useful expression in the language and the reason JSONPath beats hand-written loops for exploration.
  2. 02 Records matching a condition: $.services[?(@.healthy === false)] — filter on the array, then read the fields you want off the result.
  3. 03 One field from every record: $.services[*].port, or $..services..port when the array might be nested under something you do not know yet.
  4. 04 The shape of a repeated record: $.services[0] gives one full object, which is usually the better thing to paste into schema inference than the whole list.
  5. 05 Everything under a subtree: $.owner..* — a quick way to list values when a document came from an API you do not trust.
  6. 06 Working the other way: in tree mode, select a node and use the selection menu's Copy path action to get the exact expression for it, then trim the last step into a filter.

NOTE Results are always a list. $.project gives ["Aurora API"], not "Aurora API", and a miss gives [] rather than an error. Anything you do with the output — counting, exporting, comparing — should assume a list of zero or more matches, which is also why an expression that looks right and returns [] is the failure mode to watch for.

TOOL MATRIX

Tools for this guide

Keyboard shortcuts
FORMATTING
Format input Ctrl/⌘ + Enter
Toggle auto-format Ctrl/⌘ + Shift + A
CLIPBOARD & FILES
Copy output Ctrl/⌘ + K
Open JSON file Ctrl/⌘ + O
Download output Ctrl/⌘ + S
Save snippet Ctrl/⌘ + Shift + N
MODULES
Open find & replace Ctrl/⌘ + Shift + F
Lock / unlock output Ctrl/⌘ + Shift + L
Show this dialog Ctrl/⌘ + /
Local history
Save snippet
Erase local data

Nothing is stored in this browser yet.

Removes the saved draft, history, snippets and formatting options for this site. Documents you typed stay in the editor until the page reloads.