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
More yq commands
-
yq '.spec.replicas' deployment.yamlPrint one value from a YAML file
-
yq -i '.spec.replicas = 3' deployment.yamlChange a field directly in the file (-i)
-
yq -i '.spec.containers[0].env += {"name":"DEBUG","value":"true"}' deployment.yamlAdd the DEBUG env var to the first container
-
yq -i 'del(.metadata.annotations."kubectl.kubernetes.io/last-applied-configuration")' resource.yamlRemove the last-applied-configuration annotation from a manifest
-
yq eval-all 'select(fileIndex==0) * select(fileIndex==1)' base.yaml override.yamlDeep-merge override.yaml into base.yaml and print the result