JSON to YAML for Kubernetes & Docker
To convert JSON to YAML for Kubernetes, paste your JSON into a converter that outputs indentation-based YAML — because YAML is a superset of JSON, every valid JSON document maps directly to a valid YAML document. Kubernetes, Helm charts, Docker Compose, and GitHub Actions all use YAML as their native config format. This guide shows you exactly how to convert and what YAML-specific gotchas to watch for.
{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "my-app",
"namespace": "default"
},
"spec": {
"replicas": 3,
"selector": {
"matchLabels": {
"app": "my-app"
}
}
}
}Why Kubernetes Uses YAML Instead of JSON
Kubernetes actually supports both JSON and YAML — all manifests are converted to JSON internally. But YAML is preferred by the community because:
How to Convert JSON to YAML — 3 Steps
JSON vs YAML — Key Syntax Differences
"name": "my-app"
name: my-app
"replicas": 3
replicas: 3
"enabled": true
enabled: true
"tags": ["web", "api"]
tags: - web - api
YAML Gotchas for Kubernetes
People Also Ask
Can Kubernetes read JSON directly?
Yes. kubectl apply -f accepts both JSON and YAML manifests — Kubernetes converts everything to JSON internally before storing it in etcd. YAML is just the community convention because it's more concise and supports comments.
How do I convert a Helm values.yaml back to JSON?
Any YAML-to-JSON converter works in reverse for this — paste the YAML in and get JSON out. This is useful when you need to feed Helm values into a tool or script that expects strict JSON input, such as jq.
What's the difference between YAML and JSON for Docker Compose?
Docker Compose only accepts YAML (docker-compose.yml) — there's no JSON equivalent. If you're generating compose files programmatically from JSON data, convert to YAML as the final step before writing the file.
Does kubectl accept JSON manifests?
Yes — kubectl apply -f deployment.json works exactly like kubectl apply -f deployment.yaml. JSON is fully supported for all kubectl commands; YAML is simply more common in the ecosystem.
Why does my Kubernetes YAML fail with an indentation error?
The most common cause is mixing tabs and spaces — YAML strictly forbids tabs for indentation. The second most common cause is inconsistent indent width; stick to 2 spaces throughout the file and most editors will catch mismatches automatically.
How do I validate Kubernetes YAML before applying it?
Run kubectl apply -f file.yaml --dry-run=client to validate syntax and schema without actually creating resources, or use kubectl apply --dry-run=server to also validate against the live cluster's admission controllers.