Last active
June 24, 2020 17:30
-
-
Save ghostsquad/c92b54455ff3e4eb689662588dac2e09 to your computer and use it in GitHub Desktop.
Yaml/Json Cheatsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
brew install jq | |
brew install yq | |
# render a helm chart to it's yaml parts | |
helm fetch --repo https://containous.github.io/traefik-helm-chart --untar --untardir ./charts traefik | |
helm template --output-dir ./manifests ./charts/traefik | |
# OR | |
helm template --output-dir ./loki-fluent-bit loki/fluent-bit | |
# given a large multi-document yaml file, convert it to a json array | |
yq r -d'*' crds.yaml --collect --tojson | jq '.' > crds.json | |
# convert a json array of kubernetes manifests into map | |
jq 'map( { (.kind + "." + .metadata.name|tostring): . } ) | add' crds.json > crds-named.json | |
# convert json to jsonnet (just the keys) | |
sed "s/\"\(\w+)\":/\1:/g" crds-named.json > crds-named.jsonnet | |
# convert a map to named yaml files | |
jsonnet -J vendor -m manifests example.jsonnet | xargs -I{} sh -c 'cat {} | yq r -P - > {}.yaml; rm -f {}' -- {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment