If your shell supports process substitution (Bash-style follows, see docs):

diff <(jq --sort-keys . A.json) <(jq --sort-keys . B.json)

Objects key order will be ignored, but array order will still matter. It is possible to work-around that, if desired, by sorting array values in some other way, or making them set-like (e.g. ["foo", "bar"]{"foo": null, "bar": null}; this will also remove duplicates).

Alternatively, substitute diff for some other comparator, e.g. cmp, colordiff, or vimdiff, depending on your needs. If all you want is a yes or no answer, consider using cmp and passing --compact-output to jq to not format the output for a potential small performance increase.

Answer from Erik on Stack Overflow
🌐
GitHub
github.com › josephburnett › jd
GitHub - josephburnett/jd: JSON diff and patch · GitHub
Usage: jd [OPTION]... FILE1 [FILE2] Diff and patch JSON files. Prints the diff of FILE1 and FILE2 to STDOUT. When FILE2 is omitted the second input is read from STDIN. When patching (-p) FILE1 is a diff.
Starred by 2.2K users
Forked by 65 users
Languages   Go 97.7% | Makefile 1.2%
🌐
Jd-tool
play.jd-tool.io
jd
Read more about the diff language here. This page is a web interface for jd. Enter two JSON values in the a.json and b.json fields and the output will be shown in the diff field. Switch the Options to patch and the diff will be applied to a.json to produce b.json.
Discussions

Jd – JSON Diff and Patch
The developer can always choose to use a shorted local alias for commonly used tools · That being said, I wonder if this is much better than difftastic that is more general purpose, but tree-aware? I suppose this one wouldn't care about JSON dictionary key ordering, at least More on news.ycombinator.com
🌐 news.ycombinator.com
31
184
September 10, 2024
diff - Using jq or alternative command line tools to compare JSON files - Stack Overflow
This is only a colorized text diff ... producing minimized copies of your JSON data (jq -cSM) and git diff'ing them. 2023-06-02T18:07:42.37Z+00:00 ... One more tool for those to which the previous answers are not a good fit, you can try jdd.... More on stackoverflow.com
🌐 stackoverflow.com
python 3.x - Diff json files and write changes - Stack Overflow
Using python I'm trying to diff two json files, update if there's a difference. I have a rough draft going but haven't found out how to update my file! import json import sys import jsondiff as jd ... More on stackoverflow.com
🌐 stackoverflow.com
Automate JSON compare
Hey I just wanted to drop two tools here that you might find useful: the first is jq (JSON Query) which is a standard command-line tool for working with JSON data. It's one of those tiny tools with a thousand-page manual full of features you'll probably never need, but if you're working with automating JSON you should definitely get an idea of what it does. The second, which is more directly useful for you, is jd (JSON Diff). A "diff" in this context is a JSON of only the values that are different. This should provide a much nicer workflow for comparing them. Here's a similar question on StackOverflow with some implementation. Hope that helps! More on reddit.com
🌐 r/learnprogramming
2
2
September 16, 2022
🌐
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.
🌐
jd
jd-tool.io
jd | produce and apply JSON structural diffs
Examples: jd a.json b.json cat b.json | jd a.json jd -o patch a.json b.json; jd patch a.json jd -set a.json b.json jd -f patch a.json b.json jd -f merge a.json b.json · Note: import only release commits (v1.Y.Z) because master can be unstable. import ( "fmt" jd "github.com/josephburnett/jd/lib" ) func ExampleJsonNode_Diff() { a, _ := jd.ReadJsonString(`{"foo":"bar"}`) b, _ := jd.ReadJsonString(`{"foo":"baz"}`) fmt.Print(a.Diff(b).Render()) // Output: // @ ["foo"] // - "bar" // + "baz" } func ExampleJsonNode_Patch() { a, _ := jd.ReadJsonString(`["foo"]`) diff, _ := jd.ReadDiffString(`` + `@ [1]` + "\n" + `+ "bar"` + "\n") b, _ := a.Patch(diff) fmt.Print(b.Json()) // Output: // ["foo","bar"] }
🌐
GitHub
github.com › marketplace › actions › jd-json-diff-and-patch
jd - JSON diff and patch - GitHub Marketplace
Usage: jd [OPTION]... FILE1 [FILE2] Diff and patch JSON files. Prints the diff of FILE1 and FILE2 to STDOUT. When FILE2 is omitted the second input is read from STDIN. When patching (-p) FILE1 is a diff.
🌐
Hacker News
news.ycombinator.com › item
Jd – JSON Diff and Patch | Hacker News
September 10, 2024 - The developer can always choose to use a shorted local alias for commonly used tools · That being said, I wonder if this is much better than difftastic that is more general purpose, but tree-aware? I suppose this one wouldn't care about JSON dictionary key ordering, at least
🌐
PyPI
pypi.org › project › jsondiff
jsondiff · PyPI
Diff JSON and JSON-like structures in Python. pip install jsondiff · >>> import jsondiff as jd >>> from jsondiff import diff >>> diff({'a': 1, 'b': 2}, {'b': 3, 'c': 4}) {'c': 4, 'b': 3, delete: ['a']} >>> diff(['a', 'b', 'c'], ['a', 'b', 'c', 'd']) {insert: [(3, 'd')]} >>> diff(['a', 'b', 'c'], ['a', 'c']) {delete: [1]} # Typical diff looks like what you'd expect...
      » pip install jsondiff
    
Published   Aug 29, 2024
Version   2.2.1
Find elsewhere
🌐
GitHub
github.com › jlevy › pdiffjson
GitHub - jlevy/pdiffjson: View and diff JSON the easy way
Just the simplest and fastest way to format, display, and diff JSON directly from the command line.
Starred by 77 users
Forked by 6 users
Languages   Shell 100.0% | Shell 100.0%
🌐
GitHub
github.com › xlwings › jsondiff
GitHub - xlwings/jsondiff: Diff JSON and JSON-like structures in Python · GitHub
Diff JSON and JSON-like structures in Python. pip install jsondiff · >>> import jsondiff as jd >>> from jsondiff import diff >>> diff({'a': 1, 'b': 2}, {'b': 3, 'c': 4}) {'c': 4, 'b': 3, delete: ['a']} >>> diff(['a', 'b', 'c'], ['a', 'b', 'c', 'd']) {insert: [(3, 'd')]} >>> diff(['a', 'b', 'c'], ['a', 'c']) {delete: [1]} # Typical diff looks like what you'd expect...
Starred by 746 users
Forked by 89 users
Languages   Python
🌐
SourceForge
sourceforge.net › projects › json-diff-and-patch.mirror
JSON diff and patch download | SourceForge.net
JSON diff and patch. jd is a command line utility and Go library for diffing and patching JSON and YAML values. It supports a native jd format (similar to a unified format) as well as JSON Merge Patch (RFC 7386) and a subset of JSON Patch (RFC 6902).
🌐
Homebrew
formulae.brew.sh › formula › jd
jd — Homebrew Formulae
brew install jd · JSON diff and patch · https://github.com/josephburnett/jd · License: MIT · Development: Pull requests · Formula JSON API: /api/formula/jd.json · Formula code: jd.rb on GitHub ·
🌐
GitHub
github.com › zgrossbart › jdd
GitHub - zgrossbart/jdd: A semantic JSON compare tool · GitHub
JSON Diff sorts, formats, and compares two JSON documents to find the actual semantic differences instead of just the text ones. ... You can also run JSONDiff in a Docker container if you want to run it in your data center or just on your laptop.
Starred by 1.2K users
Forked by 200 users
Languages   JavaScript 84.4% | HTML 8.4% | CSS 6.5%
🌐
Go Packages
pkg.go.dev › github.com › josephburnett › jd › lib
jd package - github.com/josephburnett/jd/lib - Go Packages
Diff describes how two JsonNodes differ from each other. A Diff is composed of DiffElements (hunks) which describe a difference at a given Path. Each hunk stands alone with all necessary Metadata embedded in the Path, so a Diff rendered in native jd format can easily be edited by hand.
🌐
GitHub
github.com › kulabun › jd
GitHub - kulabun/jd: JSON diff and patch
import ( "fmt" jd "github.com/josephburnett/jd/lib" ) func ExampleJsonNode_Diff() { a, _ := jd.ReadJsonString(`{"foo":"bar"}`) b, _ := jd.ReadJsonString(`{"foo":"baz"}`) fmt.Print(a.Diff(b).Render()) // Output: // @ ["foo"] // - "bar" // + "baz" } func ExampleJsonNode_Patch() { a, _ := jd.ReadJsonString(`["foo"]`) diff, _ := jd.ReadDiffString(`` + `@ [1]` + "\n" + `+ "bar"` + "\n") b, _ := a.Patch(diff) fmt.Print(b.Json()) // Output: // ["foo","bar"] }
Author   kulabun
🌐
Go Packages
pkg.go.dev › github.com › josephburnett › jd
jd command - github.com/josephburnett/jd - Go Packages
February 9, 2025 - Usage: jd [OPTION]... FILE1 [FILE2] Diff and patch JSON files. Prints the diff of FILE1 and FILE2 to STDOUT. When FILE2 is omitted the second input is read from STDIN. When patching (-p) FILE1 is a diff. Options: -color Print color diff. -p Apply patch FILE1 to FILE2 or STDIN.
🌐
OpenClass
open.openclass.ai › resource › lesson-61d4cd5d0eefc550e0582e8f
OpenClass Lesson - JSON 4: JD
JSON 4: JD · Completed · Did you like this lesson? (Voting helps us personalize your learning experience!) JSON 3: JQ ·
🌐
GitHub
github.com › josephburnett › jd › blob › master › README.md
jd/README.md at master · josephburnett/jd
Usage: jd [OPTION]... FILE1 [FILE2] Diff and patch JSON files. Prints the diff of FILE1 and FILE2 to STDOUT. When FILE2 is omitted the second input is read from STDIN. When patching (-p) FILE1 is a diff.
Author   josephburnett
🌐
Stack Overflow
stackoverflow.com › questions › 73654879 › diff-json-files-and-write-changes
python 3.x - Diff json files and write changes - Stack Overflow
So in the end you want that file 2 is identical to file 1. Calculating the differences is pointless, just make a copy of file 1. ... Sorry for the late response.. deadlines at work... ... import jsondiff as jd from jsondiff import diff # open and load files with open(one, "r") as f, open(two, "r") as f2: file_one = json.load(f) file_two = json.load(f2) # get differences in file_two (file_one being the master) differences = (file_two, file_one) # in order to access $update from differences use jd.update update = differences[jd.update] # assuming there are updates, loop through and update them accordingly for x in update: file_two.update({x : update[x]}) # Open a new file and write the updated contents of file_two outfile = open(outfile, "w") json.dump(file_two, outfile, indent=4)
🌐
Reddit
reddit.com › r/learnprogramming › automate json compare
r/learnprogramming on Reddit: Automate JSON compare
September 16, 2022 -

Hey all,

So I’m taking over a role for a coworker managing content for our site in AEM. We have three AEM environments: we make changes in the lower one and push it to the middle environment to test it before pushing the middle to production.

Part of the testing involves comparing JSONs between the lower and middle environments to ensure they match. Right now, we do this in Notepad++ by copying the JSON code from each environment and doing a simple compare. This is incredibly time consuming so I am looking to automate the process. Something as simple as, here’s a list of lower/middle environment JSONs side by side; compare these and return if they match or not.

I typically work in Excel and code in VBA since it’s a program everyone in the enterprise has so there’s no special access required. In researching I’ve noticed Python makes JSON compare pretty easy but I haven’t really seen any automated JSON compare code. Could anyone point me in the right direction?

Thanks all!