Skip to main content
Skip table of contents

Getting started with DeltaJSON - NPM Package

You can also use the power of DeltaJSON directly in your code using our NPM package. DeltaJSON is the most powerful JSON comparison tool in NPM with configuration options and JSON result file combining all data from both documents with changes inline for easy processing. Download from NPM here:
deltajson - npm (npmjs.com)

Installation

Sign up here to get a subscription if you haven’t already:
DeltaJSON NPM Sign-up - DeltaXML
Login and get your token file and place this in the same folder as the root directory of your project. To install the deltajson package, navigate to your desired location in your terminal, and type the following commands.

CODE
npm install deltajson
npm link

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.

CODE
echo 'DeltaJSON_Auth.json' >> .gitignore

Getting started in Node

Import the package in your .js file

CODE
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:

CODE
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, or in further detail on our DeltaJSON documentation.


Getting started on the command Line

Once you have signed up, download and place the token file in the same folder as the package.

Navigate in the terminal to the same directory that the package is in and run this command. This will run a preset sample to give you an example of how the comparison works.

CODE
npm run sample

The above sample will run a basic comparison. This is an example of the sample running the below code:

CODE
deltajson compare samples/fileA.json samples/fileB.json result.json

You can replace fileA and fileB with your own files and give it a try.

CODE
deltajson compare [Path/to/your/first/JSON] [Path/to/your/second/JSON] [Result Name].json

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.

CODE
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.

  1. npmjson

  2. compare

  3. Path the first json file

  4. Path to second json file

  5. Result file name

CODE
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.

CODE
let result = await deltajson.compare('fileA.json','fileB.json',{"wordByWord":"true"});
CODE
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)

CODE
let result = await deltajson.compare('fileA.json','fileB.json',{"arrayAlignment":"Orderless"});
CODE
deltajson compare fileA.json fileB.json result.json arrayAlignment=orderless

typeWithValuePriority

CODE
let result = await deltajson.compare('fileA.json','fileB.json',{"arrayAlignment":"Orderless"});
CODE
deltajson compare fileA.json fileB.json result.json arrayAlignment=typeWithValuePriority

positionPriority

CODE
let result = await deltajson.compare('fileA.json','fileB.json',{"arrayAlignment":"positionPriority"});
CODE
deltajson compare fileA.json fileB.json result.json arrayAlignment=positionPriority

Find out more about how arrayAlignment works in our DeltaJSON documentation.


dxConfig

dxConfig is used for additional transformations of the json file, for instructions on how to use this setting, go to our website

CODE
let result = await deltajson.compare('fileA.json','fileB.json',{"dxConfig":"[path/to/dxconfig.json]" or 
"dxConfig":"{ \"dxConfig\" : [{ \"ignoreChanges\" : \"delete\",\"key\" : \"hobbies\" }]}"});
CODE
deltajson compare fileA.json fileB.json result.json dxConfig=""
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.