caohanyang / json_diff_rfc6902 Goto Github PK
View Code? Open in Web Editor NEWThis is the framework to handle JSON diff and patch based on RFC6902
License: GNU Lesser General Public License v3.0
This is the framework to handle JSON diff and patch based on RFC6902
License: GNU Lesser General Public License v3.0
const { diff } = require('json-diff-rfc6902');
const before = {
a: 'text',
}
const after = {
a: 'text',
b: undefined
};
diff(before, after);
crashes with
.\node_modules\json-diff-rfc6902\lib\unchangedArea.js:71
if (newValue.toString() === value) {
^
TypeError: Cannot read property 'toString' of undefined
at Object.findValueInUnchanged (.\node_modules\json-diff-rfc6902\lib\unchangedArea.js:71:17)
at generateObjectDiff (.\node_modules\json-diff-rfc6902\JSON-Diff.js:127:35)
at generateDiff (.\node_modules\json-diff-rfc6902\JSON-Diff.js:51:5)
at diff (.\node_modules\json-diff-rfc6902\JSON-Diff.js:33:3)
By my opinion, this lib could easily be the most complete json diff/patch library, if the published algorithm is correct this lib is based on.
How to reproduce:
var obj = [ "thisisbad", { choices: [ { choices: [] } ] } ]; jdr.apply(obj, [{ op: "move", from: "/0", path: "/0/choices/0/choices/0" }]);
Result: Uncaught TypeError: Cannot read property '0' of undefined
Expected result:
[ { "choices": [ { "choices": [ "thisisbad" ] } ] } ]
Hi,
first let me thank you for this one, it generates the most clever diffs among all the similar libs i checked. As an extra, it is able to apply patches.
Please consider to implement a "public" get(object, path) method that calculates JSON Pointer, so this lib will cover all basic features people need when working with JSON patches.
In the simple example, a weird "copy" patch is calculated as a diff what is wrong. Check it on codepen or here:
var a = {
choices: [
{id: "2"}
]
};
var b = {
choices: [
{id: "2"}
],
description: "2"
};
var diff = jdr.diff(a, b);
jdr.apply(a, diff, {OBJ_COM:false});
console.info("diff:", diff); // results [{op: "copy", path: "/description", from: "/choices/0"}]
console.info("this should be b:", a); // results something else than b
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.