Skip to content

Instantly share code, notes, and snippets.

@kholisrag
Last active July 13, 2021 13:16
Show Gist options
  • Save kholisrag/ab7c56c2b36b94e41195f573d623dce9 to your computer and use it in GitHub Desktop.
Save kholisrag/ab7c56c2b36b94e41195f573d623dce9 to your computer and use it in GitHub Desktop.
convert yaml file to one line, useful for kubectl patch --type=json

Pre-requisite :

  • Python3
  • Pip
pip3 install pyyaml

test.yaml

- configMap:
    defaultMode: 420
    name: grafana-dashboards
  name: grafana-dashboards

convert to oneline with :

cat test.yaml | python3 -c 'import json, sys, yaml ; y = yaml.safe_load(sys.stdin.read()) ; print(json.dumps(y))'

[{"configMap": {"defaultMode": 420, "name": "grafana-dashboards"}, "name": "grafana-dashboards"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment