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,982 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

TypeScript
70%
Other

Budibase

Low Code Platforms · No Code Platforms

28,324

Build AI agents, automations, and internal apps on a single open-source platform with full self-hosting control.

View details
91
Repo Health
81
Technical
63
Dependency
Built with
TypeScript 70%
Svelte 26%
Updated 1 weeks ago
TypeScript
62%
Other

Flowise

AI Development · Automation · Developer Tools

55,490

Drag-and-drop visual builder for AI agents, RAG pipelines, and multi-agent systems—deploy anywhere in minutes.

View details
82
Repo Health
77
Technical
63
Dependency
Built with
TypeScript 62%
JavaScript 27%
Updated 1 months ago
TypeScript
48%
AGPL 3.0

Grafana

Analytics · Monitoring

76,962

The open-source observability platform that unifies metrics, logs, and traces from any data source into dynamic, queryable dashboards.

View details
95
Repo Health
91
Technical
63
Dependency
Built with
TypeScript 48%
Go 46%
Updated 4 days ago
TypeScript
97%
Other

GrowthBook

Ab Testing Experimentation · Analytics · Developer Tools

8,446

Open source feature flags, A/B testing, and warehouse-native experimentation that queries your existing data infrastructure—no data movement required.

View details
92
Repo Health
85
Technical
63
Dependency
Built with
TypeScript 97%
Updated 4 days ago
TypeScript
97%
Other

Lightdash

Analytics · Data Engineering

6,166

The open-source Looker alternative that turns your dbt project's metrics and dimensions into governed, self-serve charts and dashboards — no license key required.

View details
93
Repo Health
84
Technical
64
Dependency
Built with
TypeScript 97%
Updated 4 days ago
Rust
56%
Apache 2.0

Magnitude

AI Development · Developer Tools

5,285

An open source inference engine that profiles your hardware, recommends the best local models, and tunes them for the coding agent you already use.

View details
78
Repo Health
83
Technical
71
Dependency
Built with
Rust 56%
TypeScript 18%
Python 11%
Updated 4 days ago
TypeScript
88%
Apache 2.0

Medplum

Authentication · Databases · Developer Tools

2,709

An open-source, FHIR-native healthcare platform that gives developers a compliant backend, authentication, a React component library, and serverless bots to build clinical applications in weeks instead of years.

View details
93
Repo Health
90
Technical
72
Dependency
Built with
TypeScript 88%
Updated 5 days ago
TypeScript
92%
Other

n8n

Automation · No Code Platforms

206,147

Code when you need it, UI when you don't — the workflow automation platform built for technical teams who refuse to choose.

View details
95
Repo Health
87
Technical
65
Dependency
Built with
TypeScript 92%
Updated 4 days ago
TypeScript
51%
ZLIB

Portainer

Devops

38,590

A lightweight, open-source web UI that puts Docker, Kubernetes, and Podman management within reach of any team—no CLI expertise required.

View details
92
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 51%
Go 38%
Updated 1 weeks 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