構造化データ(JSON/YAML/TOML/XML/INI/CSV)の意味的差分ツール。キー順序や空白を無視し、本質的な変更のみを表示。
従来の diff は構造を理解しません:
$ diff config_v1.json config_v2.json
< {
< "name": "myapp",
< "version": "1.0"
< }
> {
> "version": "1.1",
> "name": "myapp"
> }キーの順序が変わっただけで全行が差分として表示されます。
diffx は意味的な変更だけを表示:
$ diffx config_v1.json config_v2.json
~ version: "1.0" -> "1.1"# CLIツールとして
cargo install diffx
# ライブラリとして(Cargo.toml)
[dependencies]
diffx-core = "0.6"# 基本
diffx file1.json file2.json
# 出力例
~ version: "1.0" -> "1.1"
+ features[0]: "new-feature"
- deprecated: "old-value"JSON, YAML, TOML, XML, INI, CSV(拡張子で自動判定、--format で明示指定可)
--output json|yaml # 機械可読な出力
--quiet # 差分有無を終了コードのみで返す(0:同じ, 1:差分あり)
--ignore-keys-regex RE # 正規表現にマッチするキーを無視
--array-id-key KEY # 配列要素をKEYで識別して比較
--epsilon N # 浮動小数点の許容誤差
--ignore-case # 大文字小文字を無視
--ignore-whitespace # 空白の違いを無視
-r, --recursive # ディレクトリを再帰比較+追加-削除~変更!型変更
# 設定ファイルの変更検知
if ! diffx config/prod.json config/staging.json --quiet; then
echo "設定が変更されています"
diffx config/prod.json config/staging.json --output json > changes.json
fi
# タイムスタンプやメタデータを無視して比較
diffx api_v1.json api_v2.json --ignore-keys-regex "^(timestamp|updated_at)$"diffx-cli/tests/cmd/ に詳細な例があります:
MIT