SyntaxDock guide

JSONPath Syntax Guide: RFC 9535 Examples

Learn RFC 9535 JSONPath with practical child selectors, wildcards, filters, and array slices. Read normalized paths and distinguish missing matches from null.

Start with one sample JSON document

The JSONPath Tester has separate JSON and expression editors. Paste this document into JSON, enter a query, and select Test JSONPath. Values and normalized result paths are calculated locally; the document is never uploaded.

{
  "items": [
    { "name": "dock", "price": 8, "note": null },
    { "name": "lamp", "price": 15 },
    { "name": "cable", "price": 3 }
  ],
  "owner": { "name": "Alex" }
}

Select children and use wildcards

$ selects the complete document. $.owner.name selects "Alex"; $['owner']['name'] expresses the same lookup. Quoted bracket notation also addresses keys containing spaces or punctuation. A missing key, such as $.missing, gives no match.

Combine child selectors with an array wildcard to select every item name:

$.items[*].name

The result contains three matches, each with its location and value:

[
  {
    "path": "$['items'][0]['name']",
    "value": "dock"
  },
  {
    "path": "$['items'][1]['name']",
    "value": "lamp"
  },
  {
    "path": "$['items'][2]['name']",
    "value": "cable"
  }
]

Find descendants and select array indexes

$..name searches descendants and finds all three item names and the owner name: four matches. Use $.items[0] for the dock item and $.items[-1] for the cable item. An out-of-range index such as $.items[99] produces no match. Array order is defined, but do not rely on a particular order for object wildcard members.

Filter matching items

Inside a filter, @ denotes the candidate being tested. Select names with prices below ten:

$.items[?@.price < 10].name

Two items match:

[
  {
    "path": "$['items'][0]['name']",
    "value": "dock"
  },
  {
    "path": "$['items'][2]['name']",
    "value": "cable"
  }
]

$.items[?(@.price < 10)].name is also supported and gives the same two matches. RFC 9535 permits parentheses to group logical expressions. Combine conditions with &&, ||, and !.

Standard functions have typed arguments: length() measures string, array or object size; count() counts nodes; value() converts a singular nodelist to its value; match() tests a whole string and search() tests a substring using regular expressions. For example, $.items[?length(@.name) == 4] selects the dock and lamp objects, two matches. The cable name has five characters. Functions are interpreted as JSONPath, never evaluated as JavaScript.

Select array slices

$.items[0:2] selects the first two item objects; the end index is exclusive. Add a child selector to get only their names:

$.items[0:2].name

The two selected names are:

[
  {
    "path": "$['items'][0]['name']",
    "value": "dock"
  },
  {
    "path": "$['items'][1]['name']",
    "value": "lamp"
  }
]

$.items[::2] selects every second item: dock and cable, two matches. A negative step, as in $.items[::-1], selects all three objects in reverse order: cable, lamp, dock. Slices operate on arrays, not strings.

Read normalized result paths

SyntaxDock displays a JSON array of path and value pairs, not just a list of values. For the first name, $['items'][0]['name'] identifies its location independently of the wildcard, filter, or slice that found it. Normalized paths use quoted member names and concrete array indexes. Result order follows the JSONPath nodelist; repeated selections remain repeated.

Distinguish zero matches from JSON null

The first item has a note member whose value is JSON null:

$.items[0].note

This succeeds with Matches: 1:

[
  {
    "path": "$['items'][0]['note']",
    "value": null
  }
]

The second item has no note member:

$.items[1].note

This also succeeds, with Matches: 0 and an empty result:

[]

Neither query produces a diagnostic. Zero matches is a successful query result, not a syntax error. Check key spelling and filter conditions when a result is unexpectedly empty. A selected null is a value, not a missing match.

Use RFC 9535 rather than JavaScript dialect extensions

SyntaxDock implements RFC 9535. Parenthesized logical filters are supported, but script selectors such as $.items[(@.length-1)] are rejected with jsonpath.expression.invalid and no output. Arbitrary JavaScript calls and executable expressions are unsupported; do not assume a query from another dialect is portable.

For the formal grammar and semantics, see the RFC 9535 specification.

Understand input and display limits

JSON comments and trailing commas are invalid. The workspace accepts up to 2 MiB of JSON and an 8 KiB expression, measured as UTF-8 bytes, and displays up to 1,000 matches with total and displayed counts when truncated. Use the tool's examples to explore supported selectors before adapting a query from another library.