JSONPath tester
4 matches
$.store.book[0].price 8.95$.store.book[1].price 12.99$.store.book[2].price 8.99$.store.bicycle.price 19.95Evaluated in your browser · nothing is uploaded
Runs a JSONPath expression against a JSON document and lists every match with the concrete path it came from — so when `$..price` returns four numbers, you can see which four things they belong to.
How to test a JSONPath expression
JSONPath was proposed as a JSON equivalent of XPath, and unlike XPath it was never formally standardised until recently — which is why implementations disagree. The supported grammar here is stated rather than implied: `$`, `.key`, `['key']`, `[0]`, `[-1]`, `[start:end]`, `[*]`, `..` for recursive descent, and filters of the form `?(@.field == value)` with `==`, `!=`, `<`, `<=`, `>`, `>=`, or a bare `@.field` meaning "has a truthy value". What it deliberately does not do is evaluate filters as code. The original proposal implemented them by handing the expression to the host language’s `eval`, and most small libraries copied that — which means a JSONPath expression from an untrusted source is arbitrary code execution. The filters here are parsed and applied, so the grammar is smaller and nothing is ever evaluated. The recursive descent operator is where the real power is and also where the surprises are. `$..price` finds every price at any depth, including ones you did not think of — the bicycle as well as the books — and that is usually what you want and occasionally exactly not.
Questions
Only recently, as RFC 9535. Implementations that predate it disagree, particularly about filters and descent.