Skip to content

Javascript implementation of JSON diff according to RFC6902

License

Notifications You must be signed in to change notification settings

SpotDraft/rfc6902-json-diff-js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON diff according to RFC6902

Build Status

Diff two JS objects and receive an RFC6902 JSON patch.

var diff = require("rfc6902-json-diff");

var patch = diff(
  { name: "CQQL", age: 21, likes: ["api stuff"] },
  { name: "CQQL", age: 22, likes: ["api stuff", "json"] }
);

console.log(patch);
//=> [{ op: "replace", path: "/age", value: 22 },
//=>  { op: "add", path: "/likes/1", value: "json" }]

Implementation

The current implementation only uses the add, remove and replace operation. Usage of move and copy can and may be added later and I am always open for pull requests, but they are not needed to generate patches for every possible modification. Your patches will just be a bit bigger than they would be with move and copy.

Arrays are diffed with the Levenshtein distance. This gives us

diff([1, 2, 3, 4, 5, 6], [1, 5, 2, 3, 4, 6]) == [
  { op: "add", path: "/1", value: 5 },
  { op: "remove", path: "/5" }
]

instead of 5 replace operations.

About

Javascript implementation of JSON diff according to RFC6902

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%