Use jq to first sort all keys. Then diff to do the diffing:

jq -S . A.json > A-sorted.json
jq -S . B.json > B-sorted.json
diff A-sorted.json B-sorted.json

The above example is for Linux but both jq and diff is available for Windows. It seems Windows has an alternative diff tool called fc, perhaps this could be used instead of diff.

Answer from Jacob on Stack Exchange
🌐
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.
Discussions

diff - Using jq or alternative command line tools to compare JSON files - Stack Overflow
Are there any command line utilities that can be used to find if two JSON files are identical with invariance to within-dictionary-key and within-list-element ordering? Could this be done with jq or More on stackoverflow.com
🌐 stackoverflow.com
Comparing two json files : shell scripting - Stack Overflow
I would like to write a shell script which would compare the two line by line and whenever it finds a difference, output the line number where the difference occurred. ... To compare json files you should convert them so they have same order of keys. More on stackoverflow.com
🌐 stackoverflow.com
Compare json files
There's the jq tool you can use to print out a json with sorted keys jq -S . A.json. Then compare the results with any text-diffing tool you like. On my linux I'd maybe do diff <(jq -S . A.json) <(jq -S . B.json) More on reddit.com
🌐 r/json
5
4
March 20, 2024
command line - CLI tool to compare 2 JSON files without regards to order of data objects AND returns an errorlevel environment variable - Software Recommendations Stack Exchange
I'm searching for a CLI (Windows) tool to compare 2 JSON files. The trick is that the data objects within the JSON files may be in different orders (positions). Even if the order of data objects c... More on softwarerecs.stackexchange.com
🌐 softwarerecs.stackexchange.com
🌐
GitHub
github.com › espadrine › json-diff
GitHub - espadrine/json-diff: Compute the difference between two JSON-serializable Ruby objects. · GitHub
Allows computing reverse operations without the source JSON. moves*: include move operations. Set it to false to remove clutter. additions*: include add operations. Set it to false to remove clutter. original_indices*: array indices are those from the source array (for from fields, or path fields on remove operations) or the target array (for other path fields). It eases manual checking of differences.
Starred by 80 users
Forked by 10 users
Languages   Ruby 99.6% | Makefile 0.4%
🌐
GitHub
github.com › jlevy › pdiffjson
GitHub - jlevy/pdiffjson: View and diff JSON the easy way
Use brew install jq colordiff on Mac, apt-get install jq colordiff or equivalent on Linux. Install the script anywhere you like. Simplest: ... Or copy pjson and pdiffjson to /usr/local/bin by hand! $ pdiffjson Usage: pdiffjson [--sort-arrays] [diff options] file1.json file2.json Show pretty-printed, colored diff of normalized JSON.
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. Options: -color Print color diff. -p Apply patch FILE1 to FILE2 or STDIN.
Starred by 2.2K users
Forked by 65 users
Languages   Go 97.7% | Makefile 1.2%
🌐
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.
🌐
JSON Compare
jsoncompare.org
JSON Compare - Best JSON Diff Tools
It helps to Compare and find proper different in JSON Code, JSON files. It's also a JSON Beautify your compare Data. You can also download your JSON Data. Directly copy JSON Data and paste when you want. You can undo and redo your changes. Try with our sample data. JSON Compare working proper in Windows, Mac, Linux, Chrome, Firefox, Safari and Edge and it's Free.
Find elsewhere
🌐
Lib.rs
lib.rs › crates › json_diff
json_diff — command-line utility in Rust // Lib.rs
September 22, 2020 - For readability, output is neatly differentiated into three categories: keys with different values, and keys not present in either of the objects. Only missing or unequal keys are printed in output to reduce the verbosity. ... Currently, json-diff is available through crates.io (apart from building this repo directly).
🌐
GitHub
gist.github.com › ipan › e5e86d5495f16216e31fe12ebc9532a4
compare two JSONs with jq #json #jq · GitHub
You can use: diff <(jq 'keys' file1.json) <(jq 'keys' file2.json) This will just give you the list of keys that are different.
🌐
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.
🌐
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%
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.

🌐
Liquibase
docs.liquibase.com › documentation home › reference guide › database inspection, change tracking, and utility commands › diff json
diff JSON - Liquibase
After you run the command, a JSON-structured object lists the differences between the databases, as well as the values that are configured in your Liquibase properties or Maven POM file, or are passed as command-line arguments under the --url and --reference-url keys.
🌐
Readthedocs
python-json-patch.readthedocs.io › en › latest › commandline.html
Commandline Utilities — python-json-patch 1.22 documentation
usage: jsondiff [-h] [--indent INDENT] [-v] FILE1 FILE2 Diff two JSON files positional arguments: FILE1 FILE2 optional arguments: -h, --help show this help message and exit --indent INDENT Indent output by n spaces -v, --version show program's version number and exit
🌐
GitHub
github.com › andreyvit › json-diff
GitHub - andreyvit/json-diff: Structural diff for JSON files · GitHub
% json-diff --help Usage: json-diff [-vCjfonskKp] first.json second.json Arguments: <first.json> Old file <second.json> New file General options: -v, --verbose Output progress info -C, --[no-]color Colored output -j, --raw-json Display raw JSON encoding of the diff -f, --full Include the equal sections of the document, not just the deltas --max-elisions COUNT Max number of ...s to show in a row in "deltas" mode (before collapsing them) -o, --output-keys KEYS Always print this comma separated keys, with their value, if they are part of an object with any diff -x, --exclude-keys KEYS Exclude these comma separated keys from comparison on both files -n, --output-new-only Output only the updated and new key/value pairs (without marking them as such).
Starred by 1.2K users
Forked by 138 users
Languages   CoffeeScript 66.6% | JavaScript 33.4%
🌐
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
🌐
Jsonutils
jsonutils.org › json-diff.html
JSON Diff Tool - Compare & Analyze JSON | JSON Utils
Compare and diff two JSON objects. Side-by-side visualization of additions, deletions, modifications. Free JSON comparison tool.