json-differences

1.0.4 • Public • Published

JSON Differences

It finds out the differences between two JSONs

Installation

npm install json-differences

Usage

In JS

var JSONDifferences = require("json-differences");

var jsonDiffer = new JSONDifferences.default();

var _old = {
    'id': 15,
    'boo': 'baa',
    'laa': 'lii'
};
var _new = {
    'id': 15,
    'boo': 'bee',
    'jaa': 'joo'
};

var diff = jsonDiffer.getJsonDiff(_old, _new);

console.log(diff);

in TS

import JsonDiffer from 'json-differences';

const jsonDiffer = new JsonDiffer();

const _old = {
    'id': 15,
    'boo': 'baa',
    'laa': 'lii'
};

const _new = {
    'id': 15,
    'boo': 'bee',
    'jaa': 'joo'
};

const diff = jsonDiffer.getJsonDiff(_old , _new);

console.log(diff);

Output

{
  new: {
    jaa: 'joo'
  },
  updated: {
    boo: {old: 'baa', new: 'bee' } 
  },
  deleted: {
    laa: 'lii' 
  }
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Package Sidebar

Install

npm i json-differences

Weekly Downloads

20

Version

1.0.4

License

ISC

Unpacked Size

16.8 kB

Total Files

5

Last publish

Collaborators

  • juanpireslima