deltajson
v1.0.3
Published
A powerful JSON comparision tool
Downloads
9
Readme
*Use of this product requires a license
deltajson
DeltaJSON is a powerful tool used to accurately compare the differences between two json files. With superior results for unordered array comparison, combined with a JSON output format for ease of use in further transformation of results.
Getting a free DeltaJSON subscription
For DeltaJSON to work you will need a token file.
To get this file head to our website to sign up and download your token file. If you already have a subscription head to DeltaJSON App to get your token file.
Installation
To install the DeltaJSON package, navigate to your desired location in your terminal, and type the following commands.
npm install deltajson
npm link deltajson
In your development environment, place the token file in the root directory of your project. Make sure you add the filename to your .gitignore file.
echo 'DeltaJSON_Auth.json' >> .gitignore
Get Started
Getting started in Node
Import the package in your .js file
import deltajson from 'deltajson'
Once that has been completed, the function deltajson.compare() will be available for you to use. Here is an example of how to use the compare function:
let Result = await deltajson.compare('/Path/to/fileA.json','/Path/to/fileB.json')
Your JSON will be compared and the result can then be further processed as required. Note: the compare function is calling a rest service, you will need to use the "await/async" functions to be able to receive the results.
Now you are ready to configure your comparison using additional parameters which are described below in the Usage section.
Getting started on the command Line using deltajson command
The above sample will run a basic comparison. This is an example of the sample running the below code:
deltajson compare node_modules/deltajson/samples/fileA.json node_modules/deltajson/samples/fileB.json result.json
You can replace fileA and fileB with your own files and give it a try.
deltajson compare [/Path/to/your/first/fileA.json] [/Path/to/your/second/fileB.json] [/Path/to/your/results/result.json]
Getting started on the command Line using sample
If you want explore DeltaJSON parameters we have provided a sample below.
Download and place the token file in the same folder as the installed node package. This would normally be node_modules/deltajson
. When that has been completed you will be able to run the sample.
Navigate in the terminal to the same folder as the installed node package and run this command. This will run a preset sample to give you an example of how the comparison works.
npm run sample
Configuration
Configuration parameters for each operation
|Parameters|Options|Default| |--------|--------|------| |wordByWord|true/false|false| |arrayAlignment|Orderless/Type With Value/Position|Orderless| |dxConfig|ignoreChanges|null|
Usage
Default JSON Comparison
When using the package in node the following lines will do the default comparison and return a json.
import deltajson from 'deltajson'
let Result = await deltajson.compare('/Path/to/fileA.json','/Path/to/fileB.json')
When using the command line, the following fields are all required and should be typed in in the following order. This will do a comparison with the default parameters set.
- npmjson
- compare
- Path to first json file
- Path to second json file
- Result file name
deltajson compare fileA.json fileB.json result.json
wordByWord
The parameter wordByWord will give you a more granualar result. This is set to false by default.
let result = await deltajson.compare('fileA.json','fileB.json',{"wordByWord":"true"});
deltajson compare fileA.json fileB.json result.json wordByWord=true
Click here for more information on how wordByWord works.
arrayAlignment
This parameter gives you control over how items in arrays are matched for comparison. The options for arrayAlignment are as follows:
- orderless(default)
let result = await deltajson.compare('fileA.json','fileB.json',{"arrayAlignment":"Orderless"});
deltajson compare fileA.json fileB.json result.json arrayAlignment=orderless
- typeWithValuePriority
let result = await deltajson.compare('fileA.json','fileB.json',{"arrayAlignment":"Orderless"});
deltajson compare fileA.json fileB.json result.json arrayAlignment=typeWithValuePriority
- positionPriority
let result = await deltajson.compare('fileA.json','fileB.json',{"arrayAlignment":"positionPriority"});
deltajson compare fileA.json fileB.json result.json arrayAlignment=positionPriority
Click here for more information on how arrayAlignment works.
dxConfig - To specify ignore changes
dxConfig is used for additional transformations of the json file like ignoring changes, for instructions on how to use this setting, go to our documentation
let result = await deltajson.compare('fileA.json','fileB.json',{"dxConfig":"[path/to/dxconfig.json]" or
"dxConfig":"{ \"dxConfig\" : [{ \"ignoreChanges\" : \"delete\",\"key\" : \"hobbies\" }]}"});
deltajson compare fileA.json fileB.json result.json dxConfig=""