🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

deep-diff-patch

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deep-diff-patch

Compute a minimal JSON-serializable diff between objects and apply it as a patch

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
2
-60%
Maintainers
1
Weekly downloads
 
Created
Source

deep-diff-patch

Compute a minimal JSON-serializable diff between objects and apply it as a patch

Install

npm install deep-diff-patch

Usage

import {diff, patch} from 'deep-diff-patch';

const oldObject = {name: 'Alice', age: 30, city: 'NYC'};
const newObject = {name: 'Alice', age: 31, email: 'alice@test.com'};

const operations = diff(oldObject, newObject);
//=> [
//   {op: 'replace', path: '/age', value: 31},
//   {op: 'add', path: '/email', value: 'alice@test.com'},
//   {op: 'remove', path: '/city'}
// ]

const result = patch(oldObject, operations);
//=> {name: 'Alice', age: 31, email: 'alice@test.com'}

API

diff(oldObject, newObject, basePath?)

Returns an array of operations describing the changes from oldObject to newObject.

Each operation has the shape {op, path, value?} where:

  • op is 'add', 'remove', or 'replace'
  • path uses JSON Pointer format (RFC 6901): /key/nested/0
  • value is present for add and replace operations

Recursively compares nested objects and arrays (by index).

patch(object, operations)

Applies an array of operations to a deep clone of object and returns the new object. The input is never mutated.

applyPatch(object, operations)

Alias for patch.

License

MIT

Keywords

diff

FAQs

Package last updated on 16 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts