Semantic diff for JSON, YAML, CSV, TOML and XML that plugs into git diff and kubectl diff.
datadiff compares the parsed data instead of the lines. Reordered keys,
reformatting and rewrapped YAML produce no noise; real changes are reported as
data paths, not line numbers.
brew install dimanovikov/datadiff/datadiff # or: cargo install datadiff
# compare two files, matching list items by their name field
datadiff old.yaml new.yaml --key name
# or make git diff use it in the current repository
git config diff.datadiff.command "datadiff --key name git-diff"
printf '*.json diff=datadiff\n*.yaml diff=datadiff\n' >> .gitattributes
# or see what kubectl apply would change, field by field
kubectl datadiff -f k8s/ --key nameNo Homebrew or Rust? See Installation for a one-line
installer and prebuilt binaries. How the git integration behaves, including
git log -p, is in Inside git diff; the kubectl plugin
is in As a kubectl plugin.
Plain diff on structured files is noisy:
- Reorder keys in a JSON object or reformat a Kubernetes manifest — and every line "changed".
- Reorder a JSON array of objects (e.g. a list of users) — and you get a wall of false positives.
- In a CSV export, one changed price hides inside a full-file text diff.
datadiff parses both files into a data tree and compares that:
- Key order and formatting are ignored.
- Arrays of objects can be matched by a key field (
--key id), so reordering is not a change. - CSV is compared row by row via a key column, reported as
row id=4217, column price: 100 → 120style entries.
| datadiff | Graphtage | dyff | difftastic | |
|---|---|---|---|---|
| Approach | structural data diff | optimal tree edit distance | YAML/JSON data diff | syntax diff for source code |
| Formats | JSON, YAML, CSV, TOML, XML | JSON, YAML, XML, CSV, … | YAML (JSON) | programming languages |
| Arrays matched by key | yes (--key id) |
heuristic, slow | no | n/a |
| 500-object JSON (73 KB) | 0.005 s | 38 s | — | — |
| Patch mode / conversion | yes | no | no | no |
| CI risk policies | yes (--fail-on) |
no | no | no |
Measured on an Apple M4 with datadiff 0.4.1 and Graphtage 0.5.0, on arrays of
objects where the new file is the old one shuffled with 1% of the entries
changed. Graphtage took 2 s for 100 objects, 9.5 s for 250 and 38 s for 500,
about four times longer for every doubling, and did not finish 1,000 objects
within two minutes. datadiff stayed under 10 ms up to 1,000 objects and
diffed 100,000 (15 MB) in 0.4 s. The tools make different trade-offs
(Graphtage finds optimal matches without being told how elements are
identified; datadiff matches structure predictably) — but for reviewing
config changes, predictable and fast wins. To reproduce, run
bench/compare_graphtage.py.
The point of datadiff is not to be another command you remember to run. Set it
up once and git diff tells the truth about config files, with no change to
how you work.
Here is the same commit three ways. Someone changed the replica count; a formatter then reordered the file.
What git diff shows you today — six changed lines, and the one that
matters is buried:
-apiVersion: apps/v1
spec:
- replicas: 3
template:
image: app:1.0
+ replicas: 5
+
+apiVersion: apps/v1What it shows with datadiff wired in:
$ git diff deploy.yaml
deploy.yaml
~ spec.replicas: 3 → 5
1 change (0 added, 0 removed, 1 modified)
And in history, where a line diff is still what you want — just without the noise:
$ git log -p deploy.yaml
apiVersion: apps/v1
spec:
- replicas: 3
+ replicas: 5
template:
image: app:1.0The reordering is gone because both sides are canonicalised before comparison.
git config diff.datadiff.command "datadiff git-diff"
git config diff.datadiff.textconv "datadiff normalize"
printf '*.json diff=datadiff\n*.yaml diff=datadiff\n' >> .gitattributesAdd --global to the git config lines to apply it everywhere, and commit
.gitattributes to share it with the repository.
You never choose at the command line — git picks by what you asked for.
| Command | What runs | Why |
|---|---|---|
git diff |
git-diff driver |
"what changed right now" wants data paths |
git log -p, git show, git blame |
normalize textconv |
history reads better as a line diff, minus the noise |
Both halves are independent: configure only command for a semantic
git diff, or only textconv for clean output everywhere including pagers
like delta.
To step around them: git diff --no-ext-diff gives a line diff of the
canonical form, and adding --no-textconv shows the file exactly as it sits
on disk.
Added and deleted files work too — git passes /dev/null for the missing
side, and datadiff reports every entry as added or removed rather than as one
opaque change.
Pass any other option ahead of the subcommand. --key matters most: without
it a reordered list of containers reads as four changes, with it as one.
git config diff.datadiff.command "datadiff --key name git-diff"A file datadiff cannot read — one that is not structured data, or one that is
invalid halfway through an edit — prints a short note and does not stop the
diff. As textconv the file passes through unchanged, so git log -p falls
back to the diff you would have seen anyway.
kubectl diff shows what kubectl apply would change in the cluster. It
writes the live objects and the would-be objects into two directories and
line-diffs them, so a manifest that only reorders its containers reads as a
rewrite. kubectl runs the program in KUBECTL_EXTERNAL_DIFF instead, and
datadiff compares two directories file by file:
export KUBECTL_EXTERNAL_DIFF="datadiff --key name"
kubectl diff -f deploy.yamlapps.v1.Deployment.default.api
~ metadata.generation: 1 → 2
~ spec.replicas: 3 → 5
~ spec.template.spec.containers[name=api].image: "nginx:1.27" → "nginx:1.28"
3 changes (0 added, 0 removed, 3 modified)
v1.ConfigMap.default.api-config
+ apiVersion: "v1"
+ data: {"feature_flags":"beta"}
+ kind: "ConfigMap"
+ metadata: {"creationTimestamp":"2026-10-07T18:27:38Z","name":"api-config","namespace":"default","uid":"11c4ba1a-b34f-4fc5-98b1-b20d769f536b"}
4 changes (4 added, 0 removed, 0 modified)
That is a real run against a kind cluster. The
new manifest also swapped the two containers and the order of the env vars,
and plain kubectl diff printed 26 changed lines for the same Deployment,
the image bump among them. Each object is printed
under kubectl's name for it, group.version.Kind.namespace.name; an object not
in the cluster yet is reported entry by entry. The exit code follows kubectl's
convention: 0 for no differences, 1 for differences, above 1 for an error.
kubectl passes on only those words of KUBECTL_EXTERNAL_DIFF made of letters,
digits, - and =, and drops the rest without a warning: --key name gets
through, a path like spec.replicas does not. Give path options through the
environment instead:
export KUBECTL_EXTERNAL_DIFF="datadiff --key name"
export DATADIFF_IGNORE=metadata.generation
export DATADIFF_FAIL_ON=spec.replicas,*.image
kubectl diff -f deploy.yaml--ignore leaves out kubectl's own bookkeeping,
and --fail-on makes the exit code 1 only
for the paths that matter, which turns kubectl diff into a drift check for
CI. If you switch an object from client-side to server-side apply, its
kubectl.kubernetes.io/last-applied-configuration annotation changes once;
ignore it with
metadata.annotations.kubectl.kubernetes.io/last-applied-configuration.
The same works for any two directories, datadiff old/ new/: files are paired
by name, a name without a known extension is read as YAML, and nested
directories are not compared.
kubectl datadiff is kubectl diff with datadiff already in place. It takes
datadiff's options as plain flags, path options included, so nothing has to
go through the environment:
kubectl datadiff -f deploy.yaml --key name --ignore metadata.generation --fail-on spec.replicasdatadiff's own options (--key, --ignore, --fail-on, --format,
--show-unchanged, --no-color, --exit-zero) go to datadiff, and every
other argument goes to kubectl diff unchanged: -f, -k, -n,
--server-side, --context and the rest. The exit code is kubectl diff's.
Install it with krew, the kubectl plugin manager:
kubectl krew install datadiffThe plugin is the datadiff binary under the name kubectl-datadiff, and
Homebrew and Nix install that name as well. With any other install, put a link
to datadiff under that name anywhere on your PATH:
ln -s "$(command -v datadiff)" ~/.local/bin/kubectl-datadiffOn Windows, copy datadiff.exe to kubectl-datadiff.exe next to it.
argocd app diff reads the same KUBECTL_EXTERNAL_DIFF variable, but calls the
program once per resource with two files (<name>-live.yaml and the desired
version) instead of two directories. It splits the variable the way a shell
would, so path options can go straight into it:
export KUBECTL_EXTERNAL_DIFF="datadiff --key name"
argocd app diff api --local ./k8s===== apps/Deployment default/api ======
~ spec.replicas: 3 → 5
~ spec.template.spec.containers[name=api].image: "nginx:1.27" → "nginx:1.28"
2 changes (0 added, 0 removed, 2 modified)
Same kind cluster, same change as above: plain argocd app diff printed 24
changed lines, because the reordered api container came out as removed and
added again. Argo CD ignores the external program's exit code and sets its own
(1 when it finds a difference), so --fail-on does not change the exit status
of argocd app diff.
Homebrew (macOS / Linux):
brew install dimanovikov/datadiff/datadiffmacOS / Linux — one command, no compiler needed (installs to
~/.local/bin):
curl -fsSL https://raw.githubusercontent.com/dimanovikov/datadiff/main/install.sh | shWindows — in PowerShell (installs to %LOCALAPPDATA%\Programs\datadiff
and adds it to the user PATH):
irm https://raw.githubusercontent.com/dimanovikov/datadiff/main/install.ps1 | iexManually — grab the archive for your platform from
GitHub Releases
(Linux x86_64/ARM, macOS Apple Silicon/Intel, Windows x86_64) and put
datadiff on your PATH.
With Rust installed:
cargo install datadiff # from crates.io
cargo install --path . # from a local checkoutkubectl plugin via krew, see As a kubectl plugin:
kubectl krew install datadiffNix (flakes):
nix run github:dimanovikov/datadiff -- old.yaml new.yaml # try it without installing
nix profile install github:dimanovikov/datadiffdatadiff <old> <new> [--key <field>] [--format <json|yaml|csv|toml|xml>]
[--show-unchanged] [--no-color] [--output <text|json|patch>]The format is autodetected from the file extension; --format overrides it.
One side can be read from stdin by passing - instead of a file. Since
stdin has no extension, --format is required:
$ kubectl get deploy -o yaml | datadiff - new.yaml --format yamlKubernetes manifests with reordered keys and one real change:
$ datadiff examples/k8s-old.yaml examples/k8s-new.yaml
~ spec.replicas: 3 → 5
1 change (0 added, 0 removed, 1 modified)A CSV price list, matched by the id column (reordering rows is free):
$ datadiff examples/products-old.csv examples/products-new.csv --key id
~ $[id=1001].price: 25.99 → 29.99
+ $[id=1006]: {"category":"electronics","id":1006,...}
- $[id=1003]: {"category":"home","id":1003,...}
3 changes (1 added, 1 removed, 1 modified)CSV has no types, so datadiff decides per column: a column holds numbers only
if every cell in it, in both files, reads as a number without losing what was
written. price above is numeric, so 29.99 and 29.990 would be equal; a
column of codes such as A-17 and 1E5, or of ZIP codes such as 00544,
stays text and is compared exactly as written.
Machine-readable output for tooling (--output json):
$ datadiff examples/k8s-old.yaml examples/k8s-new.yaml --output json
{
"changes": [
{ "type": "modified", "path": "spec.replicas", "old": 3, "new": 5 }
],
"summary": { "added": 0, "removed": 0, "modified": 1, "total": 1 }
}A diff produced with --output json can be applied to a file with the
patch subcommand. The patched document is printed to stdout as JSON:
$ datadiff old.yaml new.yaml --output json > changes.json
$ datadiff patch old.yaml changes.json > new.jsonChanges are applied by data path (users[id=4217].email); a path that
cannot be resolved in the target file is an error (exit code 2) — nothing
is skipped silently. Known limitation: object keys containing ., [ or
] cannot be patched, because such paths are not representable.
For external tooling there is also --output patch, which emits the diff
as a JSON Patch (RFC 6902) document that any json-patch implementation
can apply:
$ datadiff old.yaml new.yaml --output patch
[
{
"op": "replace",
"path": "/spec/replicas",
"value": 5
}
]Key-matched array paths (users[id=4217].email) are resolved to the
numeric indices JSON Pointer requires, looked up in the old document;
elements added by key use the RFC 6902 append syntax (/users/-).
Removals from one array are ordered by descending index so applying them
does not shift the remaining indices. The patch subcommand consumes the
native --output json format, not RFC 6902.
A JSON array of objects matched by key — pure reordering reports nothing:
$ datadiff users-old.json users-new.json --key id
0 changes (0 added, 0 removed, 0 modified)XML follows the same tree diff; attributes are reported under @name and
element text under $text (quick-xml mapping), and the root element name
is dropped. The same mapping is used when writing XML in convert, so an
XML → XML conversion round-trips (wrapped in <root>):
$ datadiff examples/config-old.xml examples/config-new.xml
~ port.$text: "8080" → "9090"
~ tls.@enabled: "false" → "true"
~ tls.@version: "1.2" → "1.3"
3 changes (0 added, 0 removed, 3 modified)Defaults can come from a .env file in the working directory
(see .env.example):
| Variable | Flag |
|---|---|
DATADIFF_KEY |
--key |
DATADIFF_FORMAT |
--format |
DATADIFF_SHOW_UNCHANGED |
--show-unchanged |
DATADIFF_NO_COLOR |
--no-color |
DATADIFF_OUTPUT |
--output |
DATADIFF_EXIT_ZERO |
--exit-zero |
DATADIFF_FAIL_ON |
--fail-on |
DATADIFF_IGNORE |
--ignore |
Priority: CLI flag > .env > built-in default.
See Inside git diff — datadiff git-diff takes git's
calling convention directly.
A shell function picking the two temp files out of git's seven arguments also works, and is what this section used to recommend:
git config diff.datadiff.command 'f() { datadiff --exit-zero "$2" "$5"; }; f'Prefer the subcommand. The shim cannot name the file it is diffing, which
makes a multi-file diff unreadable; it detects the format from git's temporary
files rather than from the real path; a file that is invalid mid-edit aborts
the whole diff instead of being skipped; and the function syntax needs a POSIX
shell, so it does not work from cmd.exe.
git difftool can hand both sides to datadiff instead of a side-by-side
tool — useful when you want the semantic summary rather than a text diff:
git difftool --no-prompt --extcmd 'datadiff --exit-zero'And to read the diff in vim (or pipe it anywhere else):
datadiff old.yaml new.yaml | vim -R -All supported formats parse into the same data tree, so files can be converted between them (the output format comes from the extension):
$ datadiff convert config.yaml config.json
$ datadiff convert rows.json rows.csvLimits: TOML needs an object at the document root (and no nulls), CSV needs
an array of flat objects, and XML needs an object at the document root.
Since parsing does not retain the XML root element name, written XML is
always wrapped in <root>. Such mismatches are reported as errors (exit
code 2).
In CI you often want the gate to fail only on risky changes, not on
cosmetic ones. --fail-on takes path patterns (repeatable or
comma-separated); the exit code is 1 only when a change path matches:
$ datadiff old.yaml new.yaml --fail-on spec.replicas,*.image
~ spec.replicas: 3 → 5
~ spec.template.labels.team: "a" → "b"
2 changes (0 added, 0 removed, 2 modified) # exit code 1: replicas matchedA pattern matches when it equals the path, is a dot-segment prefix of it
(spec matches spec.replicas), or uses * globs (*.image). Changes
that match nothing still print but exit 0.
For GitHub Actions there is a ready-made wrapper — dimanovikov/datadiff-action:
- uses: dimanovikov/datadiff-action@v1
with:
old: base/deploy/app.yaml
new: deploy/app.yaml
fail-on: spec.replicas,*.imageSome changes are never worth reading: a counter the server bumps, a
timestamp, an annotation a tool rewrites. --ignore takes the same path
patterns as --fail-on and leaves matching changes out entirely — they are
not printed, not counted and not checked against --fail-on:
$ datadiff old.yaml new.yaml --ignore metadata.generation
~ spec.replicas: 3 → 5
1 change (0 added, 0 removed, 1 modified)~ path: old → new— modified (yellow)+ path: value— added (green)- path: value— removed (red)= path— unchanged (grey, only with--show-unchanged)
Paths use dot notation (services.web.replicas); array elements are
users[3].email by index, or users[id=4217].email when matched by --key.
Scalar values are rendered in JSON representation.
0— no differences1— differences found2— error (file not found, invalid format)
The 0/1 split makes datadiff drop-in usable in CI gates and scripts.
Found a format, a path pattern or a git setup that datadiff gets wrong? Open an issue or start a discussion. If it saved you from a bad review, a star helps other people find it.
Dual-licensed under either of MIT or Apache-2.0 at your option.

