Search code examples
yamlcross-referenceindirection

Is there a way to reference a particular element in a yaml array?


Is there a way to reference a particular element in a yaml array? For example if I have this bit of yaml:

node_list:
  - one
  - two
  - three

Can I do something like this:

first_node: node_list[0]

Solution

  • Only with anchors & aliases. Example:

    node_list:
      - &first one
      - two
      - three
    first_node: *first
    

    There is no equivalent to XPath in YAML, at least not officially.