JSON-Patch

Lean, high-performance RFC 6902 JSON Patch and JSON Pointer implementation for applying, generating, validating, and observing diffs between JSON documents.

Library
npm
v3.1.1
1,983 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
51 /100 Fair
Development Activity 0
Maintenance 32
Community 72
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
69 /100 Good
Architecture 74
Code Quality 68
Innovation 72
Learning Curve 60

fast-json-patch is a small, dependency-free implementation of the JSON Patch (RFC 6902) and JSON Pointer standards for JavaScript and TypeScript. It lets you apply an array of patch operations to a document, validate a sequence of operations before applying them, and compare two object trees to generate the minimal patch that turns one into the other — all useful for syncing partial updates over HTTP PATCH requests instead of shipping whole documents.

Beyond the core apply/compare/validate functions, it ships a duplex “observe” API that watches a live JavaScript object for mutations and synchronously emits the corresponding JSON Patch operations when you call generate(). The library ships as CommonJS, native ESM, and a minified browser bundle from the same TypeScript source, and its test suite runs the official json-patch-tests conformance fixtures to guarantee strict RFC 6902 compliance across Node.js and browsers (Chrome, Firefox, Safari, Edge, IE11).

What You Get

  • applyPatch / applyOperation for applying RFC 6902 operations to a document, with optional mutation vs. clone semantics
  • compare() to diff two JSON document trees and produce the minimal patch array between them
  • validate() to check a sequence of operations against a document and surface a typed JsonPatchError on the first invalid op
  • observe()/generate()/unobserve() for a duplex change-tracking API that emits patches as an object mutates
  • Full TypeScript typings for every operation kind (add, remove, replace, move, copy, test) as a discriminated union
  • Zero runtime dependencies and parallel CommonJS, ESM, and browser-bundle builds from one source tree

Common Use Cases

  • Sending partial updates to a REST API via HTTP PATCH instead of re-uploading the whole resource
  • Computing and storing an audit trail of changes made to a JSON document over time
  • Synchronizing client and server state by diffing local and remote copies of a document
  • Implementing optimistic UI updates that can be reverted by inverting a generated patch
  • Validating incoming JSON Patch payloads from third parties before applying them to internal state

Under The Hood

Architecture

The implementation is split across three flat modules under src/: core.ts holds an operation-dispatch table (objOps/arrOps) mapping each RFC 6902 op name to a dedicated handler function, plus the public applyPatch/applyOperation/compare/validate entry points; duplex.ts layers a WeakMap-based “Mirror” shadow-copy mechanism on top of core.ts to power the observe()/generate() change-tracking API; and helpers.ts provides shared primitives (deep clone, path escaping, equality, the PatchError class) that both other modules import. There is no framework, dependency injection, or plugin system — the public index.ts simply re-exports and composes a default object from all three modules, and the design stays approachable because duplex.ts is the only layer built on top of core.ts rather than the reverse.

Tech Stack

Written in TypeScript targeting es5 (tsconfig.json) with zero runtime dependencies, the same src/ tree is compiled three ways: a CommonJS package for Node/bundlers, a native ESM build (index.mjs) produced by a custom tsc-to-mjs.sh conversion script, and a minified UMD bundle via Webpack for direct browser <script> tags. Testing runs on Jasmine through a custom —experimental-modules runner (jasmine-run.mjs) and includes a Sauce Labs pipeline for real cross-browser verification against Chrome, Firefox, Safari, Edge, and IE11.

Code Quality

The test suite is extensive — roughly 4,700 lines of Jasmine specs across core, duplex, and validation behavior — and additionally runs the official json-patch-tests conformance fixtures vendored under test/spec/json-patch-tests/ to guarantee strict RFC 6902 compliance. Error handling is explicit via a dedicated PatchError/JsonPatchError class rather than swallowed exceptions, and typings are thorough, modeling each operation kind as a discriminated union with a dedicated typingsSpec.ts test verifying the .d.ts surface compiles. There is no linter or formatter configuration checked in, and CI is a legacy Travis pipeline rather than a modern equivalent, consistent with the repo’s currently low commit activity despite its long history.

API Design The public surface is a small, consistent set of top-level functions (applyPatch, applyOperation, compare, validate, observe, generate) that all operate directly on a plain JS document with no required setup or configuration boilerplate, and a mutateDocument flag lets callers opt into either in-place mutation or a cloned result from the same call. The README documents every function with a runnable example, and both CommonJS and ESM entry points work without a bundler. The main friction point is the observe/generate duplex API, whose WeakMap+Mirror internals are powerful but less discoverable than the straightforward apply/compare functions, and represent an older idiom relative to newer Proxy-based change-tracking approaches.

Used by 14 apps in this directory

Rust
72%
Apache 2.0

Rivet

AI Agents · Developer Tools

6,326

Stateful actors as a primitive for AI agents, real-time collaboration, and durable execution — with in-memory state, WebSockets, queues, and scheduling built in.

View details
87
Repo Health
81
Technical
64
Dependency
Built with
Rust 72%
TypeScript 25%
Updated 5 days ago
TypeScript
96%
Other

superglue

AI Agents · Data Engineering · Developer Tools

2,066

superglue is an AI-agent-driven integration engine that turns plain-English descriptions of enterprise systems into production-grade API tools, ERP/CRM connectors, and data pipelines — self-hosted or cloud, Y Combinator-backed (W25).

View details
42
Repo Health
79
Technical
67
Dependency
Built with
TypeScript 96%
Updated 2 months ago
HTML
68%
AGPL 3.0

ToolJet

AI Agents · Low Code Platforms · No Code Platforms

41,123

Open-source AI-native platform to build and deploy internal tools, workflows, and AI agents with a visual drag-and-drop builder and 80+ data source integrations.

View details
94
Repo Health
81
Technical
63
Dependency
Built with
HTML 68%
JavaScript 20%
Updated 5 days ago
TypeScript
97%
Apache 2.0

Unleash

Ab Testing Experimentation · Developer Tools · Devops

13,899

The open-source feature management platform that lets you ship code to production and control who sees it — without redeploying.

View details
91
Repo Health
84
Technical
69
Dependency
Built with
TypeScript 97%
Updated 6 days ago
TypeScript
87%
Other

Webiny JS

Blogging · CMS · Ecommerce

8,047

Open-source, self-hosted CMS on AWS serverless — a TypeScript framework you extend with code, not a product you configure through a UI.

View details
90
Repo Health
86
Technical
61
Dependency
Built with
TypeScript 87%
JavaScript 12%
Updated 6 days ago

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