Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

jsondiffer

Total Downloads 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>

Example

Running example:

npm run example {simple, stress}

Usage

Method:

getDiff(oldStruct, newStruct)

Returns the structural diff between oldStruct and newStruct.

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": {
        "oldvalue": "black",
        "newvalue": "red"
      }
    },
    {
      "color/color2": {
        "oldvalue": "brown",
        "newvalue": "blue"
      }
    }
  ]
}
You can’t perform that action at this time.