jsonpointer

Get and set nested JSON values using RFC 6901 JSON Pointer path strings

Library
npm
v5.0.1
197stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
58/100Fair
Development Activity56
Maintenance36
Community60
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
74/100Good
Architecture70
Code Quality76
Innovation60
Learning Curve88

jsonpointer is a minimal implementation of RFC 6901 (JSON Pointer) for Node.js, providing get and set functions that resolve slash-delimited path strings like /bar/baz or /qux/0 against a plain JavaScript object or array. Rather than writing manual property-chain traversal or optional-chaining code, callers pass a string path and get back (or write) the value at that location, including support for the - array-append token defined by the spec. A compile(path) helper precompiles a pointer into a reusable object with its own .get/.set methods for repeated lookups against the same path.

What You Get

  • jsonpointer.get(obj, pointer) to resolve a slash-delimited path string against an object and return the value
  • jsonpointer.set(obj, pointer, value) to write a value at the location described by a pointer string, including array indices
  • Support for the RFC 6901 - token to append to the end of an array via set
  • jsonpointer.compile(pointer) to precompile a path once into an object with bound get/set methods for repeated use
  • Bundled TypeScript type declarations (jsonpointer.d.ts)

Common Use Cases

  • Applying JSON Patch (RFC 6902) operations, which reference target locations using JSON Pointer strings
  • Resolving $ref-style or config-driven paths into nested application state or JSON Schema documents without writing custom traversal code
  • Reading or updating a specific field deep inside a large JSON API response or config object by path string rather than bracket/dot chains
  • Building generic diff, patch, or form-binding utilities that need to address arbitrary nested locations in a JSON document

Under The Hood

Architecture The entire implementation is one file (jsonpointer.js, ~2.5KB) built around a single parse helper that splits a pointer string on / and unescapes ~1/~0 tokens, with get/set walking the resulting token array through the target object one property at a time, and compile caching a parsed token array behind an object exposing bound get/set closures.

Tech Stack Plain CommonJS JavaScript with no runtime dependencies, hand-written TypeScript declarations (jsonpointer.d.ts) shipped alongside the implementation, standard for linting and a plain test.js (no test framework) run via node test.js, plus semantic-release for publishing.

Code Quality test.js exercises get/set against nested objects and arrays including the RFC’s - append token and ~0/~1 escaping edge cases, the module has no external dependencies to introduce vulnerabilities, and the code has been stable enough that the last functional release was in 2022 with only maintenance pushes since.

API Design The API surface is deliberately tiny — get(obj, pointer), set(obj, pointer, value), and compile(pointer) — mirroring the RFC’s own terminology so anyone who has read RFC 6901 can use the library immediately, and the README’s five-line example covers every common case (nested object, array index, undefined lookup, array append).

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search