npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@sdxc/jsonpath

v2026.10.25

Published

RFC 9535 JSONPath queries over JSON values, with normalized paths and every function extension

Readme

@sdxc/jsonpath

RFC 9535 JSONPath queries over JSON values, with normalized paths and every function extension.

JSONPath selects nodes from a JSON value with expressions like $.store.book[[email protected] < 10].title. This package implements the whole standard: name, wildcard, index, slice and filter selectors; child and descendant segments; comparisons and logical operators; and the length, count, match, search and value functions, with match and search reading I-Regexp patterns. It passes the official JSONPath compliance test suite.

Installation

npm add @sdxc/jsonpath

Fallible calls return @sdxc/result values.

Usage

Run a query once

import { query } from "@sdxc/jsonpath";

query({ users: [{ name: "Ada", admin: true }, { name: "Alan" }] }, "$.users[[email protected]].name");
// success([{ value: "Ada", location: ["users", 0, "name"], path: "$['users'][0]['name']" }])

Parse once, select many times

import { JSONPath } from "@sdxc/jsonpath";
import { unwrap } from "@sdxc/result";

let cheap = unwrap(JSONPath.parse("$..book[[email protected] < 10].title"));

cheap.values(store); // ["Sayings of the Century", "Moby Dick"]
cheap.values(otherStore);

Functions

import { JSONPath } from "@sdxc/jsonpath";
import { unwrap } from "@sdxc/result";

unwrap(JSONPath.parse("$.books[?length(@.title) > 15]"));
unwrap(JSONPath.parse("$.books[?count(@.authors[*]) >= 2]"));
unwrap(JSONPath.parse("$.users[?match(@.email, '[a-z]+@example\\.com')]"));
unwrap(JSONPath.parse("$.books[?search(@.title, 'Rings')]"));
unwrap(JSONPath.parse("$.groups[?value(@..id) == 7]"));

In match and search patterns, . matches anything but a line break, and ^ and $ anchor as the compliance suite expects. A pattern that is not an I-Regexp makes the function false.

API

JSONPath.parse(source: string): Result<JSONPath, JsonPathSyntaxError>

Parses a query, refusing everything RFC 9535 refuses: invalid syntax, whitespace before or after the query, an index outside ±(2^53 − 1), an unknown function, and a function argument of the wrong type, such as length(@.*) or comparing a query that can select several nodes.

jsonPath.select(document: JSONValue): JsonPathNode[]

The selected nodes, in the order RFC 9535 defines. Object members are visited in the order the object holds them.

jsonPath.values(document: JSONValue): JSONValue[]

The selected values alone.

jsonPath.source

The query text.

query(document: JSONValue, source: string): Result<JsonPathNode[], JsonPathSyntaxError>

JSONPath.parse and select in one call.

normalizedPath(location: readonly (string | number)[]): string

The normalized path of a location, the canonical query for one node: ["a", 0] becomes $['a'][0], with ', \ and control characters escaped.

JsonPathSyntaxError

The parse failure; offset is where in the query the problem was found.

Types

JsonPathNode

{ value, location, path }: the selected value, its member names and indexes from the root, and its normalized path.

JSONValue

The JSON values a query reads.

Pattern: Patch Every Matching Node

location is the node's path as segments, which @sdxc/json-pointer turns into the pointers @sdxc/json-patch operations aim at.

import { apply } from "@sdxc/json-patch";
import { stringify } from "@sdxc/json-pointer";
import { JSONPath } from "@sdxc/jsonpath";
import { unwrap } from "@sdxc/result";

let overdue = unwrap(JSONPath.parse("$.invoices[[email protected] < '2026-01-01' && [email protected]].status"));

let patch = overdue.select(ledger).map((node) => ({
	op: "replace" as const,
	path: stringify(node.location),
	value: "overdue",
}));

let next = apply(ledger, patch);

Pattern: Let Clients Filter A Collection

A query string carries a JSONPath filter; the handler parses it once and answers 400 with the offset when it is invalid.

import { JSONPath } from "@sdxc/jsonpath";
import { isFailure } from "@sdxc/result";

async function listOrders(request: Request) {
	let filter = new URL(request.url).searchParams.get("filter") ?? "$[*]";
	let parsed = JSONPath.parse(filter);
	if (isFailure(parsed)) {
		return Response.json(
			{ error: parsed.error.message, offset: parsed.error.offset },
			{ status: 400 },
		);
	}
	return Response.json(parsed.data.values(await orders.all()));
}

Versioning

Releases are dated rather than semantic. A version is the UTC date it was published, written YYYY.M.D, so 2026.9.4 is the release from 4 September 2026. At most one release goes out per day.

Those numbers say when, not what: a later date means a later release and carries no compatibility promise. Any release may change or remove an export.

Depend on one exact date, and move it when you are ready to take the change:

{
	"dependencies": {
		"@sdxc/jsonpath": "2026.9.4"
	}
}

A caret or tilde range reads the date as major, minor and patch, so it accepts every later release in the same year. An exact version keeps the upgrade yours to schedule.

License

MIT

Author

Sergio Xalambrí