yq

Map key to its child value attribute


I have a simple YAML:

host1:
  type: A
  value: 10.0.0.1
host2:
  type: A
  value: 10.0.0.2

which I want to map key-value pairs, like this:

host1: 10.0.0.1
host2: 10.0.0.2

How can I do this using yq?


Solution

  • Apply .value to all items of the root:

    .[] |= .value
    # or
    map_values(.value)
    

    Works with both kislyuk/yq and mikefarah/yq.