It's not too hard to create a function like this. Just loop through each field in the second object, and if it's not present in the first or the value is different than the first, put that field in the return object.

var compareJSON = function(obj1, obj2) {
  var ret = {};
  for(var i in obj2) {
    if(!obj1.hasOwnProperty(i) || obj2[i] !== obj1[i]) {
      ret[i] = obj2[i];
    }
  }
  return ret;
};

You can see it in action on this demo page.

Answer from Peter Olson on Stack Overflow
🌐
JSON Diff
jsondiff.com
JSON Diff - The semantic JSON compare tool
Validate, format, and compare two JSON documents. See the differences between the objects instead of just the new lines and mixed up properties.
🌐
Js
json-diff-kit.js.org
JSON Diff Kit Playground
We cannot provide a description for this page right now
🌐
GitHub
github.com › benjamine › jsondiffpatch
GitHub - benjamine/jsondiffpatch: Diff & patch JavaScript objects · GitHub
import * as jsondiffpatch from 'jsondiffpatch'; // Only import if you want text diffs using diff-match-patch import { diff_match_patch } from '@dmsnell/diff-match-patch'; const jsondiffpatchInstance = jsondiffpatch.create({ // used to match objects when diffing arrays, by default only === operator is used objectHash: function (obj) { // this function is used only to when objects are not equal by ref return obj._id || obj.id; }, arrays: { // default true, detect items moved inside the array (otherwise they will be registered as remove+add) detectMove: true, // default false, the value of items
Author   benjamine
People also ask

What is JSDiff?
JSDiff is a free online tool for comparing JSON and JavaScript code. It uses the Myers Difference Algorithm to highlight differences between two text segments, making it easy to see what has been added, removed, or modified.
🌐
jsdiff.com
jsdiff.com › home
JSON Diff - The semantic JSON compare tool - JavaScript Text Diff ...
Is my data safe when using JSDiff?
Yes, all data processing happens locally in your browser. No data is sent to any server, ensuring complete privacy and security.
🌐
jsdiff.com
jsdiff.com › home
JSON Diff - The semantic JSON compare tool - JavaScript Text Diff ...
Is JSDiff free to use?
Yes, JSDiff is completely free to use. All processing is done locally in your browser, ensuring your data remains private and secure.
🌐
jsdiff.com
jsdiff.com › home
JSON Diff - The semantic JSON compare tool - JavaScript Text Diff ...
🌐
npm
npmjs.com › package › json-diff
json-diff - npm
-s, --sort Sort primitive values in arrays before comparing -k, --keys-only Compare only the keys, ignore the differences in values -K, --keep-unchanged-values Instead of omitting values that are equal, output them as they are -p, --precision DECIMALS Round all floating point numbers to this number of decimal places prior to comparison -h, --help Display this usage information ... var jsonDiff = require('json-diff'); console.log(jsonDiff.diffString({ foo: 'bar' }, { foo: 'baz' })); // Output: // { // - foo: "bar" // + foo: "baz" // } // As above, but without console colors console.log(jsonDiff
      » npm install json-diff
    
Published   May 15, 2023
Version   1.0.6
Author   Andrey Tarantsov
🌐
npm
npmjs.com › package › json-diff-ts
json-diff-ts - npm
Key-based array identification: Compare array elements using keys instead of indices for more intuitive diffing · JSONPath support: Target specific parts of JSON documents with precision · Atomic changesets: Transform changes into granular, independently applicable operations · Dual module support: Works with both ECMAScript Modules and CommonJS · Type change handling: Flexible options for handling data type changes · Path skipping: Skip nested paths during comparison for performance · This library is particularly valuable for applications where tracking changes in JSON data is crucial, such as state management systems, form handling, or data synchronization.
      » npm install json-diff-ts
    
Published   Mar 06, 2026
Version   4.10.0
Author   Christian Glessner
🌐
GitHub
github.com › RexSkz › json-diff-kit
GitHub - RexSkz/json-diff-kit: A better JSON differ & viewer, support LCS diff for arrays and recognise some changes as "modification" apart from simple "remove"+"add". · GitHub
You can use your own component to visualize the diff data, or use the built-in viewer: import { Viewer } from 'json-diff-kit'; import type { DiffResult } from 'json-diff-kit'; import 'json-diff-kit/dist/viewer.css'; interface PageProps { diff: [DiffResult[], DiffResult[]]; } const Page: React.FC<PageProps> = props => { return ( <Viewer diff={props.diff} // required indent={4} // default `2` lineNumbers={true} // default `false` highlightInlineDiff={true} // default `false` inlineDiffOptions={{ mode: 'word', // default `"char"`, but `"word"` may be more useful wordSeparator: ' ', // default `""`, but `" "` is more useful for sentences }} /> ); };
Author   RexSkz
🌐
JSDiff
jsdiff.com › home
JSON Diff - The semantic JSON compare tool - JavaScript Text Diff Library | Myers Algorithm Implementation
JSDiff is a free online tool designed specifically for developers. It helps you quickly compare the differences between two segments of JSON or JavaScript code, supporting highlighted display, structured presentation, and one-click merging.
Find elsewhere
🌐
GitHub
github.com › ltwlf › json-diff-ts
GitHub - ltwlf/json-diff-ts: A diff tool for JavaScript written in TypeScript. · GitHub
Key-based array identification: Compare array elements using keys instead of indices for more intuitive diffing · JSONPath support: Target specific parts of JSON documents with precision · Atomic changesets: Transform changes into granular, independently applicable operations · Dual module support: Works with both ECMAScript Modules and CommonJS · Type change handling: Flexible options for handling data type changes · Path skipping: Skip nested paths during comparison for performance · This library is particularly valuable for applications where tracking changes in JSON data is crucial, such as state management systems, form handling, or data synchronization.
Author   ltwlf
🌐
DEV Community
dev.to › keploy › diff-json-a-complete-guide-to-comparing-json-data-3e31
Diff JSON – A Complete Guide to Comparing JSON Data - DEV Community
October 15, 2024 - JSON Diff Tools and Libraries ... and processing JSON data. It can filter, query, and compare JSON directly in the terminal. • JSON-diff (npm library): This JavaScript package helps compare JSON objects and outputs differences....
🌐
npm
npmjs.com › package › json-diff-kit
json-diff-kit - npm
pnpm add terminal-kit # or make sure it's already installed in your project # Compare two JSON files, output the diff data to the terminal. # You can navigate it using keyboard like `less`. jsondiff run path/to/before.json path/to/after.json ...
      » npm install json-diff-kit
    
Published   Mar 03, 2026
Version   1.0.35
Author   Rex Zeng
🌐
GitHub
github.com › pkafel › json-diff
GitHub - pkafel/json-diff: Pure Javascript JSON diff library
Pure Javascript library for comparing two Jsons. As an output returns well define structure so you can always use it to present JSON diff in whatever way you like.
Author   pkafel
🌐
TechTutorialsX
techtutorialsx.com › 2020 › 03 › 01 › javascript-json-diff
JavaScript: JSON diff – techtutorialsx
January 25, 2025 - In this tutorial we will learn how to use the jsondiffpatch library to detect the difference between two JavaScript objects.
🌐
jQuery Script
jqueryscript.net › jquery plugins › jquery text plugins
Find The Difference Between Two JSON Snippets - JSON Diff | Free jQuery Plugins
A lightweight online JSON diff tool that compares JSON data you provide and highlights the differences between two JSON snippets.
🌐
GitHub
github.com › viruschidai › diff-json
GitHub - viruschidai/diff-json: A javascript object diff tool
A diff tool for javascript objects inspired by https://github.com/eugeneware/changeset. If a key is specified for an embedded array, the diff will be generated based on the objects have same keys. var changesets = require('diff-json'); var newObj, ...
Starred by 61 users
Forked by 15 users
Languages   CoffeeScript 99.6% | JavaScript 0.4%
🌐
Benjamine
benjamine.github.io › jsondiffpatch › demo › index.html
JsonDiffPatch
JsonDiffPatch is a free online json diff tool and npm library to compare json and get a json diff.
🌐
GitHub
github.com › andreyvit › json-diff
GitHub - andreyvit/json-diff: Structural diff for JSON files · GitHub
json-diff.js --full --raw-json <(echo '{"a":4}') <(echo '{"a":5}') { "a": { "__old": 4, "__new": 5 } } Unequal arrays and objects are replaced by their diff:
Author   andreyvit
🌐
Playcode
playcode.io › json-diff
JSON Diff Online - Free JSON Compare & Merge Tool
Fast, free, no ads ... PlayCode's JSON diff tool lets you compare and merge JSON files instantly. Unlike other tools cluttered with advertisements, our JSON compare tool is completely free and ad-free.