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
🌐
Lib.rs
lib.rs › crates › json_diff
json_diff — command-line utility in Rust // Lib.rs
September 22, 2020 - #diff #json #cli · A small diff tool utility for comparing jsons · by ksceriath · #268 in #diff · 5,079 downloads per month · Unlicense · 2.5MB 483 lines · json-diff is a command line utility to compare two jsons.
🌐
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%
🌐
npm
npmjs.com › package › json-diff-kit
json-diff-kit - npm
November 23, 2025 - You can use the CLI tool to generate the diff data from two JSON files.
      » npm install json-diff-kit
    
Published   Mar 03, 2026
Version   1.0.35
Author   Rex Zeng
🌐
npm
npmjs.com › package › json-diff-cli
json-diff-cli - npm
March 24, 2022 - json-diff-cli allows you to diff the JSON of two urls and see what the differences are.
      » npm install json-diff-cli
    
Published   Mar 24, 2022
Version   0.5.3
Author   Manthan Mallikarjun
🌐
GitHub
github.com › j-tester › json-diff-cli
GitHub - j-tester/json-diff-cli: a json diffing tool
json-diff-cli allows you to diff the JSON of two urls and see what the differences are.
Starred by 4 users
Forked by 2 users
Languages   JavaScript 100.0% | JavaScript 100.0%
🌐
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.
Find elsewhere
🌐
GitHub
github.com › jclulow › jsondiff
GitHub - jclulow/jsondiff: A simple command-line JSON diff utility
Install node.js, then simply call the script on two JSON files, like so: ... ISC. See the header in the source. ... { "c": 6, "aa": 7, "y": "diff all the things!", "z": true, "removed": { "red": true, "green": false, "blue": false }, "common": { "john": 4, "still here": true }, "equal": "!!!!", "wasarray": [ 1, 2 ,3 ,4], "stillisarray": [ 1, 1, 2, 5, 3, 4, 0, 2, 3, 2, 3, 5, 9] }
Starred by 62 users
Forked by 14 users
Languages   JavaScript 100.0% | JavaScript 100.0%
🌐
Liquibase
docs.liquibase.com › documentation home › reference guide › database inspection, change tracking, and utility commands › diff json
diff JSON - Liquibase
Then, run the following command in the CLI: ... By default, the result is sent to STDOUT, which provides flexibility to use the result in other tools or in a processing pipeline. You can also have your output in a file using the --output-file=<filename> attribute. liquibase --output-file=myfile.json diff --format=json
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.

🌐
npm
npmjs.com › package › json-diff
json-diff - npm
diff({ outputNewOnly: true } ✔ should return only new diffs (added) ✔ should return only new diffs (changed) ✔ should return only new diffs (deleted) ✔ should return only old diffs - exchanged first and second json (added) ✔ should return only old diffs - exchanged first and second json (changed) ✔ should return only old diffs - exchanged first and second json (deleted) 107 passing (74ms) 1.0.6 Comment out another debugging output. 1.0.5 Comment out debugging output(!) 1.0.4 Fix typo that broke -o/--output-keys · 1.0.3 Change from cli-color to colors to reduce package size.
      » npm install json-diff
    
Published   May 15, 2023
Version   1.0.6
Author   Andrey Tarantsov
🌐
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%
🌐
crates.io
crates.io › crates › json-compare-cli
json-compare-cli - crates.io: Rust Package Registry
May 3, 2025 - A command-line tool to compare JSON files and print the differences in a human-readable format. ... Running the above command will globally install the json-compare-cli binary.
🌐
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
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.
🌐
Reddit
reddit.com › r/golang › built a tool for deep json comparison - seeking input on array diff visualization
r/golang on Reddit: Built a Tool for Deep JSON Comparison - Seeking Input on Array Diff Visualization
July 30, 2024 -

Hey r/golang community,

I've been grappling with a recurring challenge in my work: comparing large, deeply nested JSON files. To tackle this, I created a CLI tool in Go that helps highlight differences between two JSON files with high precision.

The tool is relatively compact, about 200 lines of code, and handles different types of changes well, including additions, deletions, and type mismatches. However, I'm looking to improve how differences within arrays are displayed. Currently, if an item at the beginning of an array is modified or removed, all subsequent items are marked as changed, which isn't very helpful for quick analysis.

Here's where I could use your collective wisdom:

  1. Visualization Techniques: Does anyone have suggestions for more intuitive ways to display array differences? Maybe a method that effectively pinpoints and isolates changes without cascading the entire array?

  2. Code Feedback: I'd love to get some feedback on the implementation. I'm sure there are optimizations and best practices that I could apply to enhance the tool's performance and usability.

I'm looking forward to your insights and suggestions. Let's make JSON comparisons easier for everyone!

You can check out the tool and contribute here: https://github.com/phplego/jcmp

Thank you all in advance!

🌐
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.
🌐
crates.io
crates.io › crates › json_diff_ng
json_diff_ng - crates.io: Rust Package Registry
May 30, 2024 - A JSON diff library, featuring deep-sorting and key exclusion by regex. CLI is included.