New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jsondiffpatch

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsondiffpatch

Diff & Patch for Javascript objects

0.3.5
Source
npm
Version published
Weekly downloads
1.4M
-6.4%
Maintainers
1
Weekly downloads
 
Created

What is jsondiffpatch?

The jsondiffpatch npm package is a tool for computing the difference between two JSON objects and applying those differences to other JSON objects. It is useful for tasks such as data synchronization, version control, and change tracking in JSON data structures.

What are jsondiffpatch's main functionalities?

Diff

This feature computes the difference between two JSON objects. In this example, the difference between the 'left' and 'right' objects is calculated, resulting in a delta that shows the change in the 'age' property.

const jsondiffpatch = require('jsondiffpatch');
const left = { name: 'John', age: 30 };
const right = { name: 'John', age: 31 };
const delta = jsondiffpatch.diff(left, right);
console.log(delta);

Patch

This feature applies a delta (difference) to a JSON object to produce a new JSON object. In this example, the delta is applied to the 'left' object, resulting in the 'right' object with the updated 'age' property.

const jsondiffpatch = require('jsondiffpatch');
const left = { name: 'John', age: 30 };
const delta = { age: [30, 31] };
const right = jsondiffpatch.patch(left, delta);
console.log(right);

Unpatch

This feature reverts a JSON object to its previous state by applying the inverse of a delta. In this example, the delta is used to revert the 'right' object back to the 'left' object.

const jsondiffpatch = require('jsondiffpatch');
const right = { name: 'John', age: 31 };
const delta = { age: [30, 31] };
const left = jsondiffpatch.unpatch(right, delta);
console.log(left);

Reverse

This feature computes the inverse of a delta, which can be used to revert changes. In this example, the inverse of the delta is calculated, which can then be used to revert the changes made by the original delta.

const jsondiffpatch = require('jsondiffpatch');
const delta = { age: [30, 31] };
const reverseDelta = jsondiffpatch.reverse(delta);
console.log(reverseDelta);

Other packages similar to jsondiffpatch

Keywords

json

FAQs

Package last updated on 14 Feb 2018

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