diff json/structures in Javascript
With JsonDiffer you can differentiate two structures in Javascript/typescript:
https://github.com/lukascivil/jsondiffer
live example: http://jsondifference.lukascivil.com.br/
import {JsonDiffer} from 'json-difference';
const coffee = { color: { color1: 'black', color2: 'brown' }, special: true };
const oil = { color: { color1: 'red', color2: 'blue' }, special2: false };
const jsondifference = new JsonDiffer();
let diff = jsondifference.getDiff(coffee, oil);
console.log(JSON.stringify(diff))
Output:
{
"new": {
"special2": false
},
"removed": {
"special": true
},
"edited": [{
"color/color1": {
"newvalue": "black",
"oldvalue": "red"
}
}, {
"color/color2": {
"newvalue": "brown",
"oldvalue": "blue"
}
}]
}
Written by lukascivil
Related protips
Have a fresh tip? Share with Coderwall community!
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside