YAML to JSON


tl; dr

  • jsonは読めるけど、yamlはまだあまり読めない人が読めるようになる
  • vs codeユーザ向け

やり方

vscodeに以下をインストールします

では、早速適当なyamlファイルを変換してみましょう
(kubeのdeploymentファイルです)

  • 対象のyamlファイルを開いた状態で
  • shift + command + P を押す
  • 「YAML to JSON:Convert selection or document」と入力

すると以下のようにjsonに変換できます。
jsonが読めて、yamlはまだ苦手という方はこちらを活用してみるのもいいかもしれません。

before

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

after

{
  "apiVersion": "apps/v1",
  "kind": "Deployment",
  "metadata": {
    "name": "nginx-deployment",
    "labels": {
      "app": "nginx"
    }
  },
  "spec": {
    "replicas": 3,
    "selector": {
      "matchLabels": {
        "app": "nginx"
      }
    },
    "template": {
      "metadata": {
        "labels": {
          "app": "nginx"
        }
      },
      "spec": {
        "containers": [
          {
            "name": "nginx",
            "image": "nginx:1.14.2",
            "ports": [
              {
                "containerPort": 80
              }
            ]
          }
        ]
      }
    }
  }
}