Socket
Socket
Sign inDemoInstall

json-diff

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-diff

JSON diff


Version published
Weekly downloads
465K
increased by3.67%
Maintainers
1
Weekly downloads
 
Created

What is json-diff?

The json-diff npm package is a tool for comparing JSON objects and generating a diff between them. It is useful for identifying changes between two JSON structures, which can be helpful in various scenarios such as configuration management, data synchronization, and debugging.

What are json-diff's main functionalities?

Generate Diff

This feature allows you to generate a diff between two JSON objects. The code sample demonstrates how to use the json-diff package to compare two JSON objects and print the differences.

const jsonDiff = require('json-diff');
const oldJson = { name: 'Alice', age: 25 };
const newJson = { name: 'Alice', age: 26 };
const diff = jsonDiff.diffString(oldJson, newJson);
console.log(diff);

Pretty Print Diff

This feature allows you to generate a color-coded diff for better readability. The code sample shows how to enable color in the diff output.

const jsonDiff = require('json-diff');
const oldJson = { name: 'Alice', age: 25 };
const newJson = { name: 'Alice', age: 26 };
const diff = jsonDiff.diffString(oldJson, newJson, { color: true });
console.log(diff);

Compare JSON Files

This feature allows you to compare JSON data from files. The code sample demonstrates how to read JSON data from two files and generate a diff.

const fs = require('fs');
const jsonDiff = require('json-diff');
const oldJson = JSON.parse(fs.readFileSync('old.json', 'utf8'));
const newJson = JSON.parse(fs.readFileSync('new.json', 'utf8'));
const diff = jsonDiff.diffString(oldJson, newJson);
console.log(diff);

Other packages similar to json-diff

FAQs

Package last updated on 17 Apr 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc