GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - ali-master/json-diff-patch: JsonDiffPatch is a library that allows for the diffing and patching of JSON objects

BranchesTags
Open more actions menu

Latest commit

 

History

19 Commits
19 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.vscode
.vscode
 
 
src
src
 
 
test
test
 
 
.cspell.json
.cspell.json
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
.prettierignore
.prettierignore
 
 
.prettierrc.js
.prettierrc.js
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
eslint.config.js
eslint.config.js
 
 
package.json
package.json
 
 
pnpm-lock.yaml
pnpm-lock.yaml
 
 
tsconfig.json
tsconfig.json
 
 
tsconfig.module.json
tsconfig.module.json
 
 
vitest.config.ts
vitest.config.ts
 
 

Repository files navigation

JsonDiffPatch

JsonDiffPatch is a library that allows for the diffing and patching of JSON objects.

npm install json-diff-patch-v2
  1. Import JsonDiffPatch in your project:
import { DiffPatcher } from 'json-diff-patch-v2';
  1. Create a DiffPatcher instance:
const diffPatcher = new DiffPatcher();
  1. Use the diff, patch, and reverse methods to work with your JSON objects:
  • Diff: To find the difference between two objects.
  • Patch: To apply a patch to an object.
  • Reverse: To reverse a patch.

Examples

Diffing Two Objects

const left = { name: 'John', age: 25 };
const right = { name: 'John', age: 26 };

const delta = diffPatcher.diff(left, right);
console.log(delta);
// Output: { age: [25, 26] }

Patching an Object

const original = { name: 'John', age: 25 };
const delta = { age: [25, 26] };

const patched = diffPatcher.patch(original, delta);
console.log(patched);
// Output: { name: 'John', age: 26 }

Using Property Filter

In scenarios where you want to ignore certain properties during diffing, you can use the propertyFilter option.

const options = {
  propertyFilter: function(name) {
    return name.slice(0, 1) !== '$';
  },
};
const diffPatcherWithFilter = new DiffPatcher(options);

const left = { data: { $volatile: 123, stable: 456 } };
const right = { data: { $volatile: 124, stable: 456 } };

const delta = diffPatcherWithFilter.diff(left, right);
console.log(delta);
// Output: undefined (since the change is in a filtered property)

About

JsonDiffPatch is a library that allows for the diffing and patching of JSON objects

ali-master.github.io/json-diff-patch/

Topics

diffdiff-algorithmjsonjson-diff-patch

Resources

Readme
MIT license

Contributing

Contributing
Activity

Stars

3 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.