Deep JSON comparison, patching, and merge tool for the terminal. Zero external dependencies.
- Deep diff two JSON files (added/removed/changed keys)
- Nested objects and arrays support
- Colored terminal output
- Output as RFC 6902 JSON Patch
- Apply patches to JSON documents
- Ignore specific paths during comparison
- Sort keys before comparing
- Diff arrays by ID field (match items by key instead of index)
- Three-way merge with conflict detection
- Summarize changes (count by type)
- Compare API responses
- Pipe-compatible (reads from stdin with
-)
# Clone and use directly - no pip install needed
git clone https://github.com/Anuar-boop/json-diff.git
cd json-diff
# Make executable
chmod +x json_diff.py
# Optional: add to PATH
ln -s $(pwd)/json_diff.py /usr/local/bin/json-diff# Colored terminal output
python3 json_diff.py diff file1.json file2.json
# Output as RFC 6902 JSON Patch
python3 json_diff.py diff file1.json file2.json --patch
# Output as raw JSON
python3 json_diff.py diff file1.json file2.json --json
# Summary only (counts)
python3 json_diff.py diff file1.json file2.json --summarypython3 json_diff.py diff file1.json file2.json --ignore /metadata/timestamp /versionpython3 json_diff.py diff file1.json file2.json --sort-keysWhen arrays contain objects with a unique ID, match by that field instead of array index:
python3 json_diff.py diff users1.json users2.json --array-id id# Generate a patch
python3 json_diff.py diff old.json new.json --patch > patch.json
# Apply it
python3 json_diff.py apply original.json patch.json
# Apply and save to file
python3 json_diff.py apply original.json patch.json -o patched.jsonpython3 json_diff.py merge base.json ours.json theirs.json
# Save merged result
python3 json_diff.py merge base.json ours.json theirs.json -o merged.jsonConflicts are reported on stderr. Non-conflicting changes from both sides are merged automatically.
python3 json_diff.py compare-api response1.json response2.json
# Ignore volatile fields
python3 json_diff.py compare-api resp1.json resp2.json --ignore /timestamp /request_idcurl -s https://api.example.com/v1/data | python3 json_diff.py diff - local.json+ /users/2: {"name": "Charlie", "role": "admin"}
- /config/debug: true
~ /version:
- "1.0.0"
+ "2.0.0"
- Python 3.7+
- No external dependencies (uses
jsonandargparsefrom stdlib)