Unify JSON documents
$ npm install --save unionj
var obj1 = { 'k1': 'v1a' };
var obj2 = { 'k1': 'v1b' };
var unionj = require('unionj');
var result = unionj.add(obj1, obj2);
console.log(result.k1); // v1b
There are only two rules that drive the merge process:
- "Simple addition" rule: if a field is in one of the documents but not in the other one then that field will be in the resulting doc and get the value it holds in the doc it appears in
- "Second-over-first" rule: if a field is in both documents it will be in the resulting doc and get the value it holds in the second one
MIT © Nicola Orritos