package
Get the structural diff of two JSON objects
npm install diff-json-structureGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
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:
$ npm install diff-json-structure
diff(oldObj, newObj, [options])
Calculates the structural diff between oldObj and newObj, returning an array of parts.
Available options:
.diffJson() method supportsSimple usage:
var diff = require('diff-json-structure');
var chalk = require('chalk');
// Utility function to visually print the diff
// Tweak it at your own taste
function printDiff(parts) {
parts.forEach(function (part) {
part.value
.split('\n')
.filter(function (line) { return !!line; })
.forEach(function (line) {
if (part.added) {
process.stdout.write(chalk.green('+ ' + line) +
Usage with options.typeMapper to ignore differences of socialProvider items of the previous example:
printDiff(diff(oldObj, newObj, {
typeMapper: function (path, value, prop, subject) {
// path is a string that contains the full path to this value
// e.g.: 'libraries.jquery' and 'socialProviders[0]'
// You may return custom types here.. if nothing is returned, the normal
// flow of identifying the structure recursively will continue
if (path === 'socialProviders') {
return 'array';
}
},
}));
$ npm test
Released under the MIT License.
Estimated unpacked size across 8 packages.
616.0 kB
Includes dependencies.
6 direct · 3 outdated
^3.0.0
9.0.0
^1.0.0
1.0.0
^1.0.0
3.0.0
^4.0.0
4.2.0
^2.0.1
5.1.0
^4.0.1
4.5.0