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. Input can be fed as inline strings or through files.
🌐
GitHub
github.com › josephburnett › jd
GitHub - josephburnett/jd: JSON diff and patch · GitHub
Same as -opts='[{"setkeys":["key1","key2"]}]'. -yaml Read and write YAML instead of JSON. -port=N Serve web UI on port N -precision=N Maximum absolute difference for numbers to be equal. Same as -opts='[{"precision":N}]'. Example: -precision=0.00001 -f=FORMAT Read and write diff in FORMAT "jd" (default), "patch" (RFC 6902) or "merge" (RFC 7386) -t=FORMATS Translate FILE1 between FORMATS.
Starred by 2.2K users
Forked by 65 users
Languages   Go 97.7% | Makefile 1.2%
🌐
Liquibase
docs.liquibase.com › documentation home › reference guide › database inspection, change tracking, and utility commands › diff json
diff JSON - Liquibase
Example: liquibase diff --format=json --diffTypes=tables,indexes,views · Note: The username and password attributes are not required for connections and systems which use alternate means of authentication. Also, you can specify database credentials as part of the url attribute.
🌐
GitHub
github.com › j-tester › json-diff-cli
GitHub - j-tester/json-diff-cli: a json diffing tool
You may string multipe ignore keys together by passing along more -i or --ignore options -m, --method <method> request method (GET, POST, or DELETE) -b, --body <body> Request body (only for POST) -k, --sortkey <key> Sort any array of json objects by the specified key -t, --timeout <milliseconds> timeout for requests. defaults to 5 seconds · { "foo": { "bar": { "a": true, "b": "now u see me" } } } { "foo": { "bar": { "a": false, "c": "now you dont" } } } key left right diff --------- ------------ ------------ ------- foo.bar.c undefined now you dont added foo.bar.b now u see me undefined deleted foo.bar.a true false updated
Starred by 4 users
Forked by 2 users
Languages   JavaScript 100.0% | JavaScript 100.0%
🌐
npm
npmjs.com › package › json-diff-cli
json-diff-cli - npm
March 24, 2022 - You may string multipe ignore keys together by passing along more -i or --ignore options -m, --method <method> request method (GET, POST, or DELETE) -b, --body <body> Request body (only for POST) -k, --sortkey <key> Sort any array of json objects by the specified key -t, --timeout <milliseconds> timeout for requests. defaults to 5 seconds · { "foo": { "bar": { "a": true, "b": "now u see me" } } } { "foo": { "bar": { "a": false, "c": "now you dont" } } } key left right diff --------- ------------ ------------ ------- foo.bar.c undefined now you dont added foo.bar.b now u see me undefined deleted foo.bar.a true false updated
      » npm install json-diff-cli
    
Published   Mar 24, 2022
Version   0.5.3
Author   Manthan Mallikarjun
🌐
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.
🌐
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%
Find elsewhere
🌐
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.
🌐
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%
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.

🌐
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%
🌐
npm
npmjs.com › package › json-diff-kit
json-diff-kit - npm
November 23, 2025 - # using npm npm i json-diff-kit --save # using yarn yarn add json-diff-kit # using pnpm pnpm add json-diff-kit
      » npm install json-diff-kit
    
Published   Mar 03, 2026
Version   1.0.35
Author   Rex Zeng
🌐
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
🌐
npm
npmjs.com › package › json-diff
json-diff - npm
-s, --sort Sort primitive values ... places prior to comparison -h, --help Display this usage information ... var jsonDiff = require('json-diff'); console.log(jsonDiff.diffString({ foo: 'bar' }, { foo: 'baz' })); // Output: ...
      » npm install json-diff
    
Published   May 15, 2023
Version   1.0.6
Author   Andrey Tarantsov
🌐
Substack
codefaster.substack.com › p › json-toolkit-json-diff
json-diff - by Tyler Adams - CodeFaster
December 29, 2020 - In this post, we’ll explore json-diff (a tool from my json-toolkit), how to use it and how to write programs that use its output.
🌐
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 - Well first we need to sort these files so that tools like diff can easily compare them. But we can't just use sort; we need to sort them by the value of the genius_ids in their payload. It turns out this is quite easy with jq. To sort the exports by genius_id we can run: $ cat old_export.json | jq -csMS 'sort_by(.genius_id)[]' > sorted_old_export.json $ cat new_export.json | jq -csMS 'sort_by(.genius_id)[]' > sorted_new_export.json
🌐
GitHub
github.com › lukascivil › json-difference
GitHub - lukascivil/json-difference: A simple way to find the difference between two objects or json diff · GitHub
yarn add json-difference # If you want to play with the terminal version yarn add json-difference-cli
Starred by 57 users
Forked by 5 users
Languages   TypeScript 91.8% | JavaScript 7.3% | HTML 0.9%
🌐
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. It highlights additions, deletions, and modifications in nested JSON structures, showing context so users ...