<p>Instead of <a href="https://github.com/kubernetes/kubernetes/blob/release-1.1/docs/user-guide/managing-deployments.md#organizing-resource-configurations" rel="nofollow">this</a> YAML file, I want to pass a JSON file. What is the equivalent JSON for it? I want to use it in the <code>kubectl create -f ...</code> command:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-nginx-svc
  labels:
    app: nginx
spec:
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: nginx
---
apiVersion: v1
kind: ReplicationController
metadata:
  name: my-nginx
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
</code></pre>

<p>There are a lot of online <code>YAML</code> to <code>JSON</code> (and vice versa) converters covering 1.1 and 1.2 spec. </p>

<p>I haven't used <code>Kubernetes</code> before, but I can see that you can pass multiple documents. Basically the <code>YAML</code> structure that you use is a short version of two documents. <code>JSON</code> doesn't have an equivalent to this, so you have to break it into two separate documents (files). </p>

<p>The three dashes in <code>YAML</code> is a way of defining multiple documents. 
So basically the above is not one <code>JSON</code> oblect/file, but two. </p>

<p>The first </p>

<pre><code>{
  "apiVersion": "v1",
  "kind": "Service",
  "metadata": {
    "name": "my-nginx-svc",
    "labels": {
      "app": "nginx"
    }
  },
  "spec": {
    "type": "LoadBalancer",
    "ports": [
      {
        "port": 80
      }
    ],
    "selector": {
      "app": "nginx"
    }
  }
} 
</code></pre>

<p>And the second</p>

<pre><code>{
  "apiVersion": "v1",
  "kind": "ReplicationController",
  "metadata": {
    "name": "my-nginx"
  },
  "spec": {
    "replicas": 2,
    "template": {
      "metadata": {
        "labels": {
          "app": "nginx"
        }
      },
      "spec": {
        "containers": [
          {
            "name": "nginx",
            "image": "nginx",
            "ports": [
              {
                "containerPort": 80
              }
            ]
          }
        ]
      }
    }
  }
}
</code></pre>

<p>As a side note, since this is not useful for your purpose, in order to represent them as one <code>JSON</code> object, then you need an array. But this would mean that the <code>YAML</code> would have to change too. So in order to have this</p>

<pre><code>[
  {
    "apiVersion": "v1",
    "kind": "Service",
    "metadata": {
      "name": "my-nginx-svc",
      "labels": {
        "app": "nginx"
      }
    },
    "spec": {
      "type": "LoadBalancer",
      "ports": [
        {
          "port": 80
        }
      ],
      "selector": {
        "app": "nginx"
      }
    }
  },
  {
    "apiVersion": "v1",
    "kind": "ReplicationController",
    "metadata": {
      "name": "my-nginx"
    },
    "spec": {
      "replicas": 2,
      "template": {
        "metadata": {
          "labels": {
            "app": "nginx"
          }
        },
        "spec": {
          "containers": [
            {
              "name": "nginx",
              "image": "nginx",
              "ports": [
                {
                  "containerPort": 80
                }
              ]
            }
          ]
        }
      }
    }
  }
]
</code></pre>

<p>The <code>YAML</code> equivalent would be this</p>

<pre><code>---
-
  apiVersion: v1
  kind: Service
  metadata:
    name: my-nginx-svc
    labels:
      app: nginx
  spec:
    type: LoadBalancer
    ports:
    - port: 80
    selector:
      app: nginx
-
  apiVersion: v1
  kind: ReplicationController
  metadata:
    name: my-nginx
  spec:
    replicas: 2
    template:
      metadata:
        labels:
          app: nginx
      spec:
        containers:
        - name: nginx
          image: nginx
          ports:
          - containerPort: 80
</code></pre>
