Note:
⚠️ If you're interested in Software Bill of Materials, you might also look into Bompare
Compares the contents of two JSON files as provided in the command line.
Output is three json files, containing common elements and deltas:
- commonElements.json, contains the elements common to both file in the left as well as the one in the right
- elementsInLeftOnly.json: contains the elements which are only found in the left file
- elementsInRightOnly.json: contains the elements which are only found in the right file
Note: contents of these output files is sorted as follows:
- keys in each element of the array are sorted alphabetically
- elements in the array are sorted by their string representation.
Unlike other tools that provide a diff-like view in one file, and instead of comparing the contents of files side-by-side using a diff text tool, Compare-Json-Arrays-In-Files provides a clear overview of the common parts and deltas (to three output files), taking into consideration that the order of elements to be compared may be different between files.
Thus, if the left file would contain:
[
{"letter": "A", "digit": "1"},
{"letter": "B", "digit": "2"},
{"letter": "C", "digit": "3"}
]
and the right one would contain:
[
{"digit": "1", "letter": "A"},
{"digit": "3", "letter": "C"},
{"letter": "B", "digit": "2"}
]
then Compare-Json-Arrays-In-Files would conclude that the files have the same JSON contents.
It outputs at one glance, in the console output:
- a comparison of the number of elements read from each of the input files
- a high-level comparison based on the contents, i.e. #elements that are common, #elements that are found only in the left file, #elements were only found in the right file.
- names of the output files This overview is very useful especially when the two files contain hundreds or more elements.
v1.0.0, see CHANGELOG.md
- currently only supporting flat JSON objects (no nested structures)
- you should have Node installed (this script was tested with node v12.2.0)
- you should have yarn installed (we used version v1.19.0)
yarn compareJsonFiles [options] <leftFile> <rightFile>
Arguments | Functionality |
---|---|
leftFile | Left input .json filename used in comparison |
rightFile | Right input .json filename used in comparison |
Flag | Alias | Functionality |
---|---|---|
--verbose | Verbose output of commands and errors | |
--help | -h | Help |
--version | -v | Version |
yarn compareJsonFiles ./testData/fileWithABC.json ./testData/fileWithBCD.json --verbose
- Javascript
- This software is intended to be used standalone, as a command-line tool
Get the sources locally; in a command line, go to the root folder of this project and execute:
yarn install
yarn test
or, to get the coverage:
yarn coverage
Automatically enabled: standard
yarn lint
See CODEOWNERS
See MAINTAINERS.md
See CONTRIBUTING.md
See LICENSE.md
- json arrays comparer
- json arrays delta