YAML Diff
Compare two YAML files by meaning, with anchors, merge keys and several documents.
By Syed Mubashir Ali · Last updated
Compare Kubernetes and config YAML by meaning
Try an example compares two versions of a Kubernetes Deployment. The second has its metadata keys in another order and a comment added, which change nothing. What did change is listed with full paths:
~ $.spec.replicas: 2 → 3
~ $.spec.template.spec.containers[0].image: "registry.example.com/web:1.4.2" → "registry.example.com/web:1.5.0"
~ $.spec.template.spec.containers[0].env[0].value: "info" → "debug"
+ $.spec.template.spec.containers[0].env[1]: {"name":"FEATURE_FLAGS","value":"new-checkout"}- JSON Diff: Compare JSON documents the same way.
- Diff Checker: Compare the files as plain text, comments included.
Anchors, merge keys and several documents
An anchor (&defaults) names a block and an alias (*defaults) reuses it; a merge key (<<: *defaults) copies its keys into another mapping, where they can be overridden. YAML Diff resolves all of these first, so editing a shared block shows up at every path that uses it, and an override shows as a change only where it differs.
A file can hold several documents separated by ---, as Kubernetes manifests often do. They're compared in order, the first with the first, and each difference is labelled with its document number, such as Document 2 · $.spec.replicas.
How to Use YAML Diff
- 1Paste the original YAML on the left and the changed YAML on the right, or open a .yaml or .yml file into either side. Try an example fills both with a Kubernetes Deployment.
- 2If either side isn't valid YAML, the line and column of the problem appear under that box, with a caret under it.
- 3Read the Changes list: each difference is listed by its path, such as $.spec.replicas, with the old and new value. Comments, indentation and key order don't count.
- 4Tick Ignore array order when a list's order doesn't matter; leave it off for lists where order is meaningful, such as steps or rules.
- 5Switch to Side by side to see both documents written out the same way, anchors expanded and keys sorted, with only the real changes highlighted.
- 6Copy the changes as text for a pull request or ticket, or copy them as a JSON Patch to apply the same change with a tool such as kubectl patch.
Frequently Asked Questions
Do comments and formatting count as changes?
No. It compares the data the YAML describes, so comments, indentation, quoting and flow style ([a, b]) versus block style make no difference. Only changed values, added or removed keys and list items, and type changes are reported.
Does it understand anchors and merge keys?
Yes. Aliases (*name) are expanded and merge keys (<<) are applied before comparing, so a change to an anchored block shows up everywhere it's used. The side-by-side view writes both documents out with the anchors expanded.
Can it compare files with several documents?
Yes. Documents separated by --- are compared in order, first with first, and each difference is labelled with its document number. A document that exists on only one side is listed as one addition or removal.
Which YAML version does it follow?
YAML 1.2's core schema: yes, no, on and off stay text, and only true and false are booleans. Dates stay exactly as written instead of turning into timestamps. Some older tools follow YAML 1.1 and read yes as true, so keep that in mind if yours does.
Can I compare Kubernetes or Docker Compose files?
Yes. Paths such as $.spec.template.spec.containers[0].image show exactly which setting changed, and list items that carry a unique name, like containers and environment variables, are matched by that name even if their order changed.
What happens if my YAML is invalid?
The tool shows the line and column of the problem, such as bad indentation, a tab used for indenting or a key that appears twice, with that line and a caret under it. A repeated key is an error rather than silently keeping one value.
Is my YAML uploaded anywhere?
No. The YAML is read and compared in your browser, so configuration files with hostnames, secrets or internal settings never leave your device.
About YAML Diff
YAML files drift. A Kubernetes manifest, a Docker Compose file, a CI pipeline or an Ansible inventory gets edited by hand, reformatted by an editor and regenerated by a tool, and a line-by-line diff turns into noise: comments moved, keys reordered, a list switched from [a, b] to block style. YAML Diff compares the data instead, so it reports only the settings that changed, each with its path.
It reads YAML the way the tools that use it do. Anchors and aliases are expanded and merge keys (<<) applied before comparing, documents separated by --- are compared one by one, and list items that carry a unique name, like containers and environment variables, are matched by that name even when their order changed.
The reader follows YAML 1.2, so yes and no stay text and dates stay as written, and it refuses files whose anchors would expand to millions of values instead of freezing the page. Everything runs in your browser: configuration with hostnames and internal settings never leaves your device.