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
🌐
npm
npmjs.com › package › json-diff
json-diff - npm
May 15, 2023 - -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
🌐
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.
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 - Myers Algorithm
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 - Myers Algorithm
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 - Myers Algorithm
🌐
Js
json-diff-kit.js.org
JSON Diff Kit Playground
We cannot provide a description for this page right now
🌐
JSDiff
jsdiff.com › home
JSON Diff - The semantic JSON compare tool - Myers Algorithm
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.
🌐
GitHub
github.com › benjamine › jsondiffpatch
GitHub - benjamine/jsondiffpatch: Diff & patch JavaScript objects · GitHub
(optionally) text diffing of long strings powered by google-diff-match-patch (diff at character level) reverse a delta, unpatch (eg. revert object to its original state using a delta) ... // sample data const country = { name: 'Argentina', capital: 'Buenos Aires', independence: new Date(1816, 6, 9), }; // clone country, using dateReviver for Date objects const country2 = JSON.parse(JSON.stringify(country), jsondiffpatch.dateReviver); // make some changes country2.name = 'Republica Argentina'; country2.population = 41324992; delete country2.capital; const delta = jsondiffpatch.diff(country, cou
Author   benjamine
🌐
npm
npmjs.com › package › json-diff-ts
json-diff-ts - npm
3 weeks ago - Calculate and apply differences between JSON objects with advanced features like key-based array diffing, JSONPath support, and atomic changesets.. Latest version: 4.9.1, last published: 18 days ago.
      » npm install json-diff-ts
    
Published   Feb 15, 2026
Version   4.9.1
Author   Christian Glessner
Find elsewhere
🌐
npm
npmjs.com › package › json-diff-kit
json-diff-kit - npm
import { Differ } from 'json-diff-kit'; // or if you are using vue, you can import the differ only import Differ from 'json-diff-kit/dist/differ'; // the two JS objects const before = { a: 1, b: 2, d: [1, 5, 4], e: ['1', 2, { f: 3, g: null, h: [5], i: [] }, 9], m: [], q: 'JSON diff can\'t be possible', r: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', s: 1024, }; const after = { b: 2, c: 3, d: [1, 3, 4, 6], e: ['1', 2, 3, { f: 4, g: false, i: [7, 8] }, 10], j: { k: 11, l: 12 }, m: [ { n: 1, o: 2 }, { p: 3 }, ], q:
      » npm install json-diff-kit
    
Published   Mar 03, 2026
Version   1.0.35
Author   Rex Zeng
🌐
SemanticDiff
semanticdiff.com › online-diff › json
SemanticDiff - Online JSON Diff
The tool compares JSON objects and arrays by first parsing them into a data structure that is independent of their textual representation. This helps us ignore changes that are unrelated to the encoded values, such as adding optional commas or whitespace outside of strings.
🌐
JSON Diff
json-diff.com
JSON Diff - Compare and Find Differences in JSON Files Online
JSON Diff is a free and open-source tool to compare two JSON objects and find differences. Visualize changes in JSON files, easy and fast.
🌐
jsDelivr
jsdelivr.com › package › npm › json-diff-rfc6902
json-diff-rfc6902 CDN by jsDelivr - A CDN for npm and GitHub
May 10, 2016 - A free, fast, and reliable CDN for json-diff-rfc6902. This framework is to compare two JSON data and generate the Patch
Published   Mar 15, 2016
🌐
jsDelivr
jsdelivr.com › package › npm › json-diff
json-diff CDN by jsDelivr - A CDN for npm and GitHub
May 15, 2023 - A free, fast, and reliable CDN for json-diff. JSON diff
Published   Apr 17, 2012
🌐
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 ... in the terminal. • JSON-diff (npm library): This JavaScript package helps compare JSON objects and outputs differences. It’s widely used in Node.js environments....
🌐
Leapcell
leapcell.io › blog › how-to-compare-json-a-practical-guide
How to Compare JSON: A Practical Guide | Leapcell
July 25, 2025 - Use online tools like JSON Diff for quick visual comparisons. To prevent differences caused by key order rather than content. Yes, using libraries like deepdiff in Python or scripts with jq. Leapcell is the Next-Gen Serverless Platform for Web Hosting, Async Tasks, and Redis: ... Develop with Node.js...
🌐
GitHub
github.com › andreyvit › json-diff
GitHub - andreyvit/json-diff: Structural diff for JSON files · GitHub
-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
Author   andreyvit
🌐
DEV Community
dev.to › keploy › json-diff-comparing-and-identifying-changes-in-json-data-2m3m
JSON Diff: Comparing and Identifying Changes in JSON Data - DEV Community
January 14, 2025 - JSON diff refers to the process of identifying and analyzing the differences between two JSON files, objects, or structures. It involves comparing key-value pairs, nested arrays, and objects to detect mismatches, changes, or missing elements.
🌐
NPM Compare
npm-compare.com › deep-diff,json-diff,jsondiffpatch
deep-diff vs jsondiffpatch vs json-diff - NPM Compare
Choose deep-diff if you need a library that provides a comprehensive and detailed comparison of nested objects, including the ability to track added, deleted, and modified properties. It is particularly useful for deep comparisons and offers a clear output format for the differences found. ... Choose jsondiffpatch if you need advanced features such as the ability to apply patches to JSON objects, revert changes, or visualize differences.
🌐
CodeSandbox
codesandbox.io › s › json-diff-ts-2tx774
json-diff-ts - CodeSandbox
August 31, 2023 - Modern TypeScript JSON diff library - Zero dependencies, high performance, ESM + CommonJS support. Calculate and apply differences between JSON objects with advanced features like key-based array diffing, JSONPath support, and atomic changesets.
Published   Aug 31, 2023
🌐
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
import { Differ } from 'json-diff-kit'; // or if you are using vue, you can import the differ only import Differ from 'json-diff-kit/dist/differ'; // the two JS objects const before = { a: 1, b: 2, d: [1, 5, 4], e: ['1', 2, { f: 3, g: null, h: [5], i: [] }, 9], m: [], q: 'JSON diff can\'t be possible', r: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', s: 1024, }; const after = { b: 2, c: 3, d: [1, 3, 4, 6], e: ['1', 2, 3, { f: 4, g: false, i: [7, 8] }, 10], j: { k: 11, l: 12 }, m: [ { n: 1, o: 2 }, { p: 3 }, ], q:
Author   RexSkz