A simple way to find the difference between two objects
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
dist.browser
examples
src
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
jestconfig.json
package-lock.json
package.json
tsconfig.browser.json
tsconfig.json

README.md

jsondiffer

npm version Build Status Project Status: Active – The project has reached a stable, usable state and is being actively developed. codecov MIT License

Example

master

Installation

npm install json-difference --save

<script type="module"> 
import {JsonDiffer} from "https://rawgit.com/lukascivil/jsondiffer/master/dist.browser/jsondiffer.js";
</script>

Usage

getDiff(oldStruct, newStruct)

Returns the structural diff between oldStruct and newStruct.

Example

Simple usage:

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(diff)

Output:

{
    "new": {
        "special2": false
    },
    "removed": {
        "special": true
    },
    "edited": [{
        "color/color1": {
            "newvalue": "black",
            "oldvalue": "red"
        }
    }, {
        "color/color2": {
            "newvalue": "brown",
            "oldvalue": "blue"
        }
    }]
}