1.2.0 • Published 2 years ago

json-obj-diff v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

json-obj-diff

A tiny library to find difference between two json objects

Install

npm install json-obj-diff

Usage Example

import { jsonObjDiff } from "json-obj-diff";

const obj1 = {
  a: 1,
  b: [1],
  c: {
    d: 1,
    e: "12312",
  },
};
const obj2 = {
  a: 10,
  b: [1, 2, 3],
  c: {
    d: 10,
    e: "1",
  },
};

const diff1 = jsonObjDiff(obj1, obj2);
/* 
diff1 = {
  a: { _o: 1, _n: 10 },
  b: {
    '1': { _o: undefined, _n: 2 },
    '2': { _o: undefined, _n: 3 },
    _arr_len_o: 1,
    _arr_len_n: 3,
    _arr: true
  },
  c: { 
    d: { _o: 1, _n: 10 }, 
    e: { _o: '12312', _n: '1' } 
  }
}
*/

API :

jsonDiff(
    value1: any,
    value2: any,
    propNames: {
        oldValue: string, // default '_o',
        newValue: string, // default '_n',
        isArr: string, // default '_arr',
        arrLenOld: string, // default '_arr_len_o',
        arrLenNew: string, // default '_arr_len_n',
    }
)

Important Note :

Arrays are converted to Objects with index as key while checking array difference

🤝 Contributing

Contributions, issues and feature requests are welcome!

Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

📝 License

This project is MIT licensed.

1.2.0

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago