LoginSignup
2
1

More than 3 years have passed since last update.

YAML to JSON

Last updated at Posted at 2020-08-28

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
              }
            ]
          }
        ]
      }
    }
  }
}
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1