Multi-document YAML to array

Split a multi-document YAML into a JSON array

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

tool
yq15 commands
tags
yq

More yq commands

  • yq '.spec.replicas' deployment.yaml

    Extract a single field from YAML

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

    Modify YAML file in-place with yq v4

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

    Append an env var to the first container

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

    Remove a specific annotation from YAML

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

    Deep-merge two YAML documents

all 15 yq commands