Diff two JSON files or streams with colored terminal output. Zero dependencies, single file.
npm install -g @chengyixu/json-diff# Compare two files
json-diff old.json new.json
# Compare stdin against a file
cat data.json | json-diff - expected.json
# Sort keys before comparing (ignores key order)
json-diff --sort old.json new.json
# Compact mode (hide unchanged values)
json-diff --compact old.json new.json| Flag | Short | Description |
|---|---|---|
--help |
-h |
Show help |
--version |
-v |
Print version |
--sort |
-s |
Sort object keys before comparing |
--compact |
-c |
Compact output |
--indent <n> |
JSON indentation (default: 2) |
- Green — added keys/values
- Red — removed keys/values
- Yellow — changed values
- Cyan — string values
- Bold — key paths
# Compare API responses
curl -s https://api.example.com/v1/status | json-diff - expected.json
# Prettified large diff
json-diff --indent 2 --sort old.json new.jsonMIT