YAML Anchor / Alias Resolver

YAML’s anchor / alias / merge feature lets you DRY up configs: define a block once with &anchor, reference it elsewhere with *anchor, optionally merge into another map with <<: *anchor. Many tools resolve these on parse, but for diffing, code review, or debugging it helps to see the fully-expanded version. This resolver inlines every alias and merge so the output is anchor-free.

How to use the YAML Anchor / Alias Resolver

Paste your YAML. js-yaml parses the document (resolving all anchors and merges at parse time), then the output gets re-emitted with noRefs: true — meaning the dumper emits full copies wherever it would otherwise re-use an anchor. The result is functionally identical to the original (same data) but every reference is inlined for human reading.

About YAML Anchor / Alias Resolver

YAML anchors are powerful and easy to overuse. A Helm chart with deeply-nested anchor merges can be unreadable; a GitLab CI config that uses &job_defaults in twelve places loses clarity for anyone reviewing a PR. The resolver gives you the inlined view: see exactly what each job will execute, exactly what each Helm value evaluates to. It’s also useful when generating code from YAML — most code generators want the resolved tree, not a representation with embedded references.

The resolver also handles the <<: *anchor merge syntax, which is a special YAML 1.1 feature for merging one map into another. js-yaml resolves these on parse, so the output has the merged keys at their final location. Anchors that reference scalars (rare but valid) expand to the scalar value at each use site.

Common use cases

  • Helm chart debugging — see exactly what a complex values.yaml produces after all the anchors expand.
  • GitLab / Drone / Concourse CI review — inline the &defaults blocks so a PR reviewer can read each job’s actual behaviour.
  • Code generation — produce a JSON-friendly intermediate for tools that don’t understand anchors.
  • YAML diffing — normalise two YAMLs to anchor-free form before diffing so reorganisations of the anchor graph don’t show as content diffs.

Frequently asked questions

What if my YAML has cyclic anchors?

js-yaml detects cycles at parse and throws. There's no useful fully-expanded form for a cyclic structure, so you'll need to break the cycle in the source.

Does it preserve comments?

No \xE2\x80\x94 YAML comments are dropped by js-yaml during parse, like virtually every YAML library. Keep your original if commentary matters.

Are merge keys (<code>&lt;&lt;</code>) supported?

Yes \xE2\x80\x94 they're resolved at parse, so the output has the merged map's keys directly. This is YAML 1.1 behaviour; YAML 1.2 deprecates merge keys but most tools still support them.