https://github.com/ansteh/difference-json
prompt the diffrence of two json objects
https://github.com/ansteh/difference-json
difference json-objects
Last synced: 8 months ago
JSON representation
prompt the diffrence of two json objects
- Host: GitHub
- URL: https://github.com/ansteh/difference-json
- Owner: ansteh
- License: mit
- Created: 2016-01-14T20:53:34.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-06T21:49:51.000Z (over 8 years ago)
- Last Synced: 2024-02-22T23:46:30.345Z (over 1 year ago)
- Topics: difference, json-objects
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/ansteh/difference-json)
## Install
Using npm:
```js
npm install difference-json
```## Usage
Get the difference of arrays:
```js
var diff = require('difference-json');
var result = diff([1,2,3],[1,6,7]);
//result equals:
[{
$set: 6,
$was: 2,
$index: 1
}, {
$set: 7,
$was: 3,
$index: 2
}]
```Get the difference of simple json objects:
```js
var diff = require('difference-json');
var result = diff({
name: 'john'
},{
name: 'andre'
});
//result equals:
{
name: {
$was: 'john',
$set: 'andre'
}
}
```Get the difference of simple nested json objects:
```js
var diff = require('difference-json');
var result = diff({
role: 'customer',
basket: {
sum: 20
}
},{
role: 'customer',
basket: {
sum: 35
}
});
//result equals:
{
basket: {
sum: {
$set: 35,
$was: 20
}
}
}
```## Related
- [shape-json](https://github.com/ansteh/shape-json) - Convert json to json with a predefined scheme
- [shape-array](https://github.com/ansteh/shape-array) - Convert array to json object## License
MIT © [Andre Stehle](https://github.com/ansteh)