Skip to content

Deep diff and patch JSON objects. RFC 6902 compliant. TypeScript-first.

Notifications You must be signed in to change notification settings

jy02140251/json-diff-patch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

JSON Diff Patch

Deep diff and patch JSON objects. RFC 6902 compliant.

Installation

npm install json-diff-patch

Usage

import { diff, patch, applyPatch } from 'json-diff-patch';

const original = {
  name: 'John',
  age: 30,
  address: { city: 'NYC' }
};

const modified = {
  name: 'John',
  age: 31,
  address: { city: 'LA' },
  email: 'john@example.com'
};

// Generate diff (RFC 6902 format)
const operations = diff(original, modified);
// [
//   { op: 'replace', path: '/age', value: 31 },
//   { op: 'replace', path: '/address/city', value: 'LA' },
//   { op: 'add', path: '/email', value: 'john@example.com' }
// ]

// Apply patch
const result = patch(original, operations);

// Or apply incrementally
let doc = original;
for (const op of operations) {
  doc = applyPatch(doc, op);
}

Features

  • RFC 6902 compliant
  • Deep object comparison
  • Array diff support
  • Immutable operations
  • TypeScript-first
  • Zero dependencies

License

MIT

About

Deep diff and patch JSON objects. RFC 6902 compliant. TypeScript-first.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published