Skip to content

Latest commit

 

History

History

README.md

json-difference-cli

npm version Total Downloads MIT License

Command-line wrapper around json-difference. Computes the delta between two JSON strings and prints it to stdout.

Installation

Global (recommended for CLI use):

npm install -g json-difference-cli
# or
yarn global add json-difference-cli

One-off:

npx json-difference-cli -o "{}" -m '{"a":1}'

Usage

jd -o <original-json> -m <modified-json>

Options

Flag Alias Required Description
-o --original yes Original (old) JSON string
-m --modified yes Modified (new) JSON string

Examples

# Simple key change
jd -o '{"a":"b"}' -m '{"a":"c"}'
# delta ---> { added: [], removed: [], edited: [ [ 'a', 'b', 'c' ] ] }

# Added / removed keys
jd -o '{"a":1}' -m '{"b":2}'
# delta ---> { added: [["b", 2]], removed: [["a", 1]], edited: [] }

# Root type change
jd -o '{}' -m '[]'
# delta ---> { added: [], removed: [], edited: [["__root__", {}, []]] }

Shell quoting tip

JSON uses double quotes, so on macOS/Linux wrap the argument in single quotes:

jd -o '{"foo":"bar"}' -m '{"foo":"baz"}'

On Windows PowerShell, escape the inner quotes or use single quotes:

jd -o '{\"foo\":\"bar\"}' -m '{\"foo\":\"baz\"}'

Output format

The tool prints the delta returned by getDiff:

{
  added:   [[path, value], ...],
  removed: [[path, value], ...],
  edited:  [[path, oldValue, newValue], ...]
}

See the json-difference README for the full path format and semantics.

Related packages

Links

License

MIT © lukascivil