Skip to content

Segment: Anchors

William W. Kimball, Jr., MBA, MSIS edited this page Apr 11, 2021 · 19 revisions

When your YAML data contains Anchors, you can select them by their unique name. For example:

anchored_hash: &anchor1
  with: child
  nodes: and values

another_anchored_hash: &anchor2
  with: its
  own: children

Select the entire anchored hash, anchored_hash, via the name of its anchor: &anchor1 or /&anchor1 Note that Anchors are identified via the required & symbol.

Especially Useful for Anchor Lists

This segment type is especially useful for selecting named anchor values from the typical aliases: list, commonly used in YAML files to define a unified location for any scalar values that are used more than once elsewhere within the same YAML file. For example:

aliases:
  - &anchorA Some value
  - &anchorB Another value
  - &anchorC True
  - &anchorD 5280

You could select the value, Another value, by using its array element index -- if you knew it -- or more simply by its known anchor name, like so: aliases[&anchorB] or /aliases/[&anchorB]. Please note that the & symbol is always required to indicate an Anchor name. When selecting an Anchor from a list, the [] pair is also required.

Clone this wiki locally