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
gist.github.com › ipan › e5e86d5495f16216e31fe12ebc9532a4
compare two JSONs with jq #json #jq · GitHub
compare two JSONs with jq #json #jq. GitHub Gist: instantly share code, notes, and snippets.
🌐
GitHub
github.com › jlevy › pdiffjson
GitHub - jlevy/pdiffjson: View and diff JSON the easy way
But it can be helpful to add standard diff arguments to refine the type of output, such as: -c (contextual diff), -C2 (contextual diff with two lines of context), or -U5 (unified diff with 5 lines of context). $ Many websites like jsondiff offer JSON diff functionality but offer no command line, don’t work on large files, and are not good for sensitive data.
Starred by 77 users
Forked by 6 users
Languages   Shell 100.0% | Shell 100.0%
🌐
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%
Top answer
1 of 3
1

You can run both files through jq (available as a small Windows binary), let jq pretty-print and sort the data in both files according to your needs, and then perform an "ordinary" diff (with WinDiff, Meld, Diffuse).

the shell commands would be

 < file1.json jq  'keys' > file1.sorted.json
 < file2.json jq  'keys' > file2.sorted.json

diff file1.sorted.json file2.sorted.json

# or better

diff -q file1.sorted.json file2.sorted.json

#
#       -q, --brief
#              report only when files differ

# if output of diff -q is nonempty, files differ -> raise an error

If you know what's going on, continue with the unmodified files.

This obviously works only if the JSON objects differ only in their keys. This also assumes that the type info is preserved (e.g. the string representation of floats does not differ between the two files)

If the JSON objects differ in object values, or if the values contain nested objects (which themselves can differ in values or in subkey ordering), or if you want the order of the first-level-keys unchanged, but need to only compare the nested "value-objects" by some other criterion, you will need more complicated jq commands.
Check stackoverflow.com - some incredible jq experts there.

2 of 3
0

Did you try and take a look at GNU Diffutils (diff)? Diff specifically has the "-B" or "--ignore-blank-lines" switch, which "Ignore changes whose lines are all blank" (see also a similar question on Stack Exchange).

There are other ways and variants as well to achieve the things you mentioned, such as using Vimdiff for example.

If you want to take a programmatic approach, you might want to take a look at the Levenshtein distance, which is a metric for measuring the difference between two Strings.

🌐
SourceForge
sourceforge.net › projects › json-diff.mirror
JSON-Diff download | SourceForge.net
August 22, 2025 - Download JSON-Diff for free. Structural diff for JSON files. json-diff is a command-line tool (and library) that computes differences between two JSON documents in a user-friendly manner.
🌐
Liquibase
docs.liquibase.com › documentation home › reference guide › database inspection, change tracking, and utility commands › diff json
diff JSON - Liquibase
Starting with Liquibase 3.9.0, you can automate drift detection at scale in your database schemas with the Liquibase Secure machine-readable JSON diff output. The diff --format=json command is a Liquibase Secure extension to the Liquibase Open Source diff command.
🌐
GitHub
github.com › jclulow › jsondiff
GitHub - jclulow/jsondiff: A simple command-line JSON diff utility
A simple command-line JSON diff utility. Contribute to jclulow/jsondiff development by creating an account on GitHub.
Starred by 62 users
Forked by 14 users
Languages   JavaScript 100.0% | JavaScript 100.0%
Find elsewhere
🌐
Nilorea
nilorea.net › 2022 › 01 › 20 › compare-two-json-in-shell
Compare two json in shell – Nilorea Studio
January 20, 2022 - I did it using the JQ command line tool from https://stedolan.github.io/jq/ Exemple: list all json files from current directory and print the difference with updated jsons from updated/ directory · for user in `ls updated-users` do # print file name echo $user # simple diff <(jq -S .
🌐
Genius Engineering
genius.engineering › faster-and-simpler-with-the-command-line-deep-comparing-two-5gb-json-files-3x-faster-by-ditching-the-code
Faster and simpler with the command line: deep-comparing two 5GB JSON files 3X faster by ditching the code
December 6, 2018 - $ echo "scale=3; $(wc -l < old_export.json) / $(wc -l < new_export.json)" | bc .999 · Ok great! The old export has 99.9% of the line count of the new export, meaning the new version actually has more lines than the old export, so off to a good start. Next, we can use diff to get the percentage of lines that are different between the new and old export.
🌐
Hacker News
news.ycombinator.com › item
Faster and simpler with the command line: deep-comparing JSON files with jq | Hacker News
December 17, 2018 - Btw I'm surprised you needed -M, since I thought jq would suppress colors if it saw it wasn't writing to a tty · Even when reading the article I thought about it :)
🌐
Readthedocs
python-json-patch.readthedocs.io › en › latest › commandline.html
Commandline Utilities — python-json-patch 1.22 documentation
# inspect JSON files $ cat a.json { "a": [1, 2], "b": 0 } $ cat b.json { "a": [1, 2, 3], "c": 100 } # show patch in "dense" representation $ jsondiff a.json b.json [{"path": "/a/2", "value": 3, "op": "add"}, {"path": "/b", "op": "remove"}, {"path": "/c", "value": 100, "op": "add"}] # show patch ...
🌐
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.
🌐
Medium
medium.com › @capeta1024 › json-diff-using-jq-vimdiff-b94829de40ff
JSON Diff using jq & vimdiff. JSON is a very commonly used data… | by Ankit Deshpande | Medium
September 26, 2022 - vimdiff staging-config-sorted.json prod-config-sorted.json · Vimdiff can be replaced by any other diff tool.
🌐
Lib.rs
lib.rs › crates › json_diff
json_diff — command-line utility in Rust // Lib.rs
September 22, 2020 - $ json_diff f source1.json source2.json $ json_diff d '{...}' '{...}' Option: f : read input from json files d : read input from command line · Currently, json-diff is available through crates.io (apart from building this repo directly).
🌐
Commandlinefu
commandlinefu.com › commands › view › 24262 › get-a-diff-of-two-json-arrays
Get a diff of two json arrays Using diff
October 11, 2018 - jq is amazing for manipulating json on the commandline, but the developers have some weird ideas about how to handle shell redirections. This command works around them. Further reading: https://github.com/stedolan/jq/issues/1110 ... Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters? You must be signed in to comment. commandlinefu.com is the place to record those command-line ...
🌐
Medium
medium.com › @lucasbru › comparison-of-json-files-9b8d2fc320ca
Comparison of JSON files. Say, you want to compare to JSON files… | by Lucas Bruxxx | Medium
August 3, 2017 - cat X.json | jq -S -f walk.filter | 1.json cat Y.json | jq -S -f walk.filter | 2.json meld 1.json 2.json
🌐
Atomic Spin
spin.atomicobject.com › 2014 › 05 › 04 › json-toolbox
A Tiny Toolbox for Spelunking through JSON - Atomic Spin
November 25, 2024 - A quick look at how curl, bash, jq, and json-diff can make JSON less painful to wrangle from the command-line.