json-difference-cli
v1.9.3
Published
json-difference cli lib
Downloads
311
Readme
json-difference-cli
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-cliOne-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
json-difference— the underlying library (use directly in code)mcp-json-diff— MCP server for AI agents
Links
- Repository: https://github.com/lukascivil/json-difference
- Issues: https://github.com/lukascivil/json-difference/issues
- Changelog
License
MIT © lukascivil
