DEV Community

Dev Nestio
Dev Nestio

Posted on

JSONPath Tester: Query JSON with a Vanilla JS Engine — No Libraries

JSONPath is to JSON what XPath is to XML. I built a live JSONPath tester with a full engine written in vanilla JS — no external libraries, runs entirely in your browser.

Try it

JSONPath Tester — DevNestio

Supported syntax

Syntax Description
$ Root
.key Child property
..key Recursive descent
[n] Array index
[-n] Negative index from end
[*] Wildcard
[a,b] Union
[a:b] Slice
[?(@.key)] Existence filter
[?(@.key op val)] Comparison filter

How the engine works

Two-phase: tokenize then query.

Tokenize splits $.store.book[0].author into ['store', 'book', '[0]', 'author'].

The query function recursively consumes tokens:

  • .. (recursive descent): evaluate here AND recurse into all children
  • [*]: iterate all array items or object keys
  • [a:b]: slice with optional step
  • [?(expr)]: filter with comparison operators

Filter expression parsing

Filter conditions like [?(@.price < 10)] are parsed with regex, then the right-hand side is coerced to number or string as needed before comparison.

102 tests pass

From basic access to complex filters — all tested with Node.js assert in a standalone test file.


Part of DevNestio — 115 free browser-only developer tools.

Top comments (0)