Turn multi-document YAML into an array

Combine all documents of a multi-document YAML into one JSON array

yq -s '.' multi.yaml | yq -o=json

tool
yq15 commands
tags
yq

More yq commands

  • yq '.spec.replicas' deployment.yaml

    Print one value from a YAML file

  • yq -i '.spec.replicas = 3' deployment.yaml

    Change a field directly in the file (-i)

  • yq -i '.spec.containers[0].env += {"name":"DEBUG","value":"true"}' deployment.yaml

    Add the DEBUG env var to the first container

  • yq -i 'del(.metadata.annotations."kubectl.kubernetes.io/last-applied-configuration")' resource.yaml

    Remove the last-applied-configuration annotation from a manifest

  • yq eval-all 'select(fileIndex==0) * select(fileIndex==1)' base.yaml override.yaml

    Deep-merge override.yaml into base.yaml and print the result

all 15 yq commands