JSONPath Explained — Why This Tool Doesn't Support [0:2] Slicing
JSONPath is a query language for JSON, the equivalent of XML's XPath. First proposed by Stefan Goessner in 2007, it long lived as a "loose standard" implemented slightly differently across languages, and was only formally standardized as RFC 9535 in 2024. Because of that looseness, supported scope varies by implementation. This guide covers the full standard syntax while pinning down exactly how far this tool goes, based on its actual source code.
1. Basic syntax: what works everywhere
| Notation | Meaning |
|---|---|
$ | Root (top-level) object |
.key or ['key'] | Child field access |
..key | Recursive descent — find key at any depth |
* | Wildcard — all child elements |
[n] | The n-th element of an array (negative counts from the end) |
These five are effectively the minimum common denominator supported by every JSONPath implementation.
2. What syntax this tool actually supports (source-checked)
This tool uses its own parser that walks the path string character by character to build tokens. Looking at the actual logic, it supports: $ (root), . (child), .. (recursive descent, detecting two consecutive dots to make a recursive token), * (wildcard), [n] (integer index, negatives supported), and filter expressions of the form [?(@.key op val)] (supporting ==, !=, >, >=, <, <=, parsed with the regex /\?\(@\.(\w+)\s*(==|!=|>|>=|<|<=)\s*(.+)\)/). Even this much lets common queries like $.store.books[*].title, $..price, and [?(@.price > 10)] work fine.
3. Slicing ([0:2]) — not simply unsupported, but silently misread
Some standard JSONPath implementations (Python's jsonpath-ng, JS's jsonpath-plus, etc.) support [start:end] or [start:end:step] range slicing borrowed from Python slice syntax. Looking at this tool's bracket-handling logic, if the bracket contents are neither * nor starting with ?(, it tries to treat them as an integer index with parseInt(inner).
parseInt("0:2") in JavaScript stops parsing the moment it hits the colon and returns 0. isNaN(0) is false, so this code silently misreads [0:2] not as a "slice range" but as plain index 0 and returns just the first element. No error, not an empty result — a result different from what the user intended, with no warning. That's the crux of this bug.
So the tool's FAQ statement "slicing is not supported" is accurate, but the actual behavior isn't simply "doesn't work" — it's "misread as something else and produces a plausible value," which requires special care. A user trying to pull several items with [0:2] who doesn't check the result count can be fooled into thinking slicing worked despite getting just one element.
4. Other advanced syntax not supported in this tool
- Slicing
[start:end:step]— misread as index 0, as explained above. - Multi-index selecting several comma-separated indexes at once like
[0,2,4]— the parser treats the comma as a number-parse failure and returns an empty result. - Script expressions evaluating a JS expression like
[(@.length-1)]— not supported.
5. Practical guide: how to use this tool safely
The syntax you can definitely trust in this tool is six things: $, ./[] child access, .. recursive descent, * wildcard, single integer index (positive/negative), and the [?(@.key op val)] filter. If you need slicing, multi-index, or complex expressions, it's safer to use a full library like jsonpath-plus (JS) in real code instead of this tool. In particular, never enter a bracket expression containing a colon (:) into this tool — if you need it, split the query into individual indexes and look them up multiple times.
Frequently Asked Questions
Q. Does entering [0:2] produce an error?
A. No. It silently returns just the single element at index 0, with no error. If you tried a slice and got only one result, this misinterpretation is the likely cause.
Q. Do filter expressions support string comparison?
A. The regex parser captures the val part of @.key op val as (.+) as-is and then compares, so you can put in either a number or a string. But quote handling and logical operator (&&, ||) combination aren't supported.
Q. Does it fully comply with the RFC 9535 standard?
A. No. This tool is a lightweight custom parser and doesn't support advanced features RFC 9535 defines, such as slicing, multi-selectors, and function extensions. It supports only basic child/recursive/wildcard/index/filter.
Q. Are JSONPath and JMESPath the same thing?
A. No. JSONPath follows XPath-style path notation and is widely used but was standardized late; JMESPath is a stricter-spec query language adopted by the AWS CLI. The syntaxes are not compatible with each other.