Convert a Kubernetes Deployment between YAML and JSON
A Kubernetes Deployment manifest converted between YAML (human-readable, what you write) and JSON (what kubectl actually sends to the API server). YAML 1.2 schema, round-trip safe.
# context
Kubernetes manifests are YAML on disk because of comments and indentation, but every kubectl call serializes them to JSON before hitting the API. Converting both directions is useful when (a) a tool only accepts JSON, (b) you want to diff two manifests structurally, or (c) you are debugging why an admission webhook rejected your YAML.
# sample (JSON)
{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "web",
"labels": { "app": "web" }
},
"spec": {
"replicas": 3,
"selector": { "matchLabels": { "app": "web" } },
"template": {
"metadata": { "labels": { "app": "web" } },
"spec": {
"containers": [
{
"name": "nginx",
"image": "nginx:1.27",
"ports": [{ "containerPort": 80 }]
}
]
}
}
}
} → Open in JSON ↔ YAML converter (pre-filled)
# notes
- Use YAML 1.2 to avoid the "Norway problem" — `country: NO` parsing as boolean false.
- Quote any image tag that looks like a number: `image: "1.0"` not `image: 1.0`.
- kubectl --dry-run=client -o json gives you the JSON; this tool round-trips it without the cluster round-trip.