npm.io
0.0.15 • Published 9 years ago

json-compare

Licence
MIT
Version
0.0.15
Deps
0
Vulns
0
Weekly
0

json-match

Build Status Coverage Status Dependency Status bitHound Overall Score bitHound Code

NOTE: Currently does not support arrays

About

Compare two json object for matching deep keys, also supports regular-expression.

usage:

npm install json-compare
import compare from 'json-compare' // es6
// OR
const compare = require('json-compare') // good old es5

const source = {
    name: "Dave Amit",
    hobby: {
        game: 'The Division'
    },
    country: 'India',
};

const test = {
    name: /[a-zA-Z ]+/,
    hobby: {
        game: /Division/,
    },
    country: 'india',
};

const result = compare(source, test);
   // Result will be something like:

   {
    regExMatch: 2, // Because it matched 2 regular expressions
    exactMatch: 0, 
    fuzzyMatch: 1, // Because India to india match
    matchCount: 3, // Total keys matched
    mismatchCount: 0,
    unmatchedCount: 0,
    match: true,
    isExactMatch: false, // Because of fuzzyMatch
  }

Keywords