diff-json-structure
Get the structural diff of two JSON objects, using diff's internally which is a module used by several test frameworks.
It is considered a structural difference whenever:
- items are added or removed to objects and arrays
- the type of the item changes
Installation
$ npm install diff-json-structure
Usage
diff(oldObj, newObj, [options])
Calculates the structural diff between oldObj
and newObj
, returning an array of parts.
Available options:
- typeMapper - A function that lets you override types for specific paths
- .. and any option that diff's
.diffJson()
method supports
Examples
Simple usage:
var diff = ;var chalk = ; // Utility function to visually print the diff// Tweak it at your own taste { parts; processstdout;} var oldObject = environment: 'dev' googleAppId: 'UA-3234432-22' socialProviders: 'facebook' libraries: jquery: './node_modules/jquery' ; var newObj = environment: 'prod' dbHost: '127.0.0.1:9000' socialProviders: 'facebook' 'twitter' libraries: jquery: './node_modules/jquery/jquery' moment: './node_modules/moment/moment' ; ;
Usage with options.typeMapper
to ignore differences of socialProvider items of the previous example:
;
Tests
$ npm test
License
Released under the MIT License.