Anchor and Alias Operators
Use the alias
and anchor
operators to read and write yaml aliases and anchors. The explode
operator normalises a yaml file (dereference (or expands) aliases and remove anchor names).
yq
supports merge aliases (like <<: *blah
) however this is no longer in the standard yaml spec (1.2) and so yq
will automatically add the !!merge
tag to these nodes as it is effectively a custom tag.
Merge one map
see https://yaml.org/type/merge.html
Given a sample.yml file of:
then
will output
Merge multiple maps
see https://yaml.org/type/merge.html
Given a sample.yml file of:
then
will output
Override
see https://yaml.org/type/merge.html
Given a sample.yml file of:
then
will output
Get anchor
Given a sample.yml file of:
then
will output
Set anchor
Given a sample.yml file of:
then
will output
Set anchor relatively using assign-update
Given a sample.yml file of:
then
will output
Get alias
Given a sample.yml file of:
then
will output
Set alias
Given a sample.yml file of:
then
will output
Set alias to blank does nothing
Given a sample.yml file of:
then
will output
Set alias relatively using assign-update
Given a sample.yml file of:
then
will output
Explode alias and anchor
Given a sample.yml file of:
then
will output
Explode with no aliases or anchors
Given a sample.yml file of:
then
will output
Explode with alias keys
Given a sample.yml file of:
then
will output
Explode with merge anchors
Given a sample.yml file of:
then
will output
Dereference and update a field
Use explode with multiply to dereference an object
Given a sample.yml file of:
then
will output
Last updated