Guide · 5 min read
JSON to YAML for Kubernetes & Docker
Kubernetes, Helm charts, Docker Compose, and GitHub Actions all use YAML as their native config format. If you have a JSON config — from an API, a tool, or a legacy system — this guide shows you how to convert it to valid YAML and explains the key differences to watch out for.
JSON (Kubernetes Deployment)
YAML (ready for kubectl apply)
{
"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:
YAML supports comments: You can annotate manifests with # comments to explain parameters. JSON has no comment syntax.
YAML is less verbose: No curly braces, no quotes around simple strings, no commas — YAML files are 20–30% shorter than equivalent JSON.
YAML is the ecosystem standard: Helm, Kustomize, Argo CD, and almost every Kubernetes tooling project uses YAML by convention.
How to Convert JSON to YAML — 3 Steps
1
Paste your JSON
Open the JSON to YAML converter and paste your JSON object or config file into the left panel.
2
Convert instantly
The YAML equivalent appears on the right automatically. All nested objects become indented YAML mappings.
3
Copy and use
Copy the YAML output and paste it into your Kubernetes manifest, Helm values file, or Docker Compose config.
JSON vs YAML — Key Syntax Differences
Strings
JSON
"name": "my-app"
YAML
name: my-app
YAML does not require quotes around simple strings. Quotes are only needed when the string contains special characters like : or #.
Numbers
JSON
"replicas": 3
YAML
replicas: 3
Numbers work the same way in both formats — no quotes needed.
Booleans
JSON
"enabled": true
YAML
enabled: true
YAML also accepts yes/no and on/off as booleans in older versions. Stick to true/false for Kubernetes to avoid surprises.
Arrays
JSON
"tags": ["web", "api"]
YAML
tags: - web - api
YAML arrays use a dash - prefix for each item instead of square brackets.
YAML Gotchas for Kubernetes
⚠
Indentation must be spaces, not tabs: YAML strictly forbids tabs for indentation. Use 2 spaces consistently. Most editors can auto-convert tabs to spaces.
⚠
Colons in string values need quotes: If a string value contains a colon (e.g. a URL), wrap it in quotes: command: "http://example.com" to avoid parse errors.
⚠
Watch out for YAML boolean edge cases: Values like "on", "off", "yes", "no" are parsed as booleans in YAML 1.1. Always use true/false explicitly in Kubernetes manifests.
⚠
Multiline strings use | or >: Use | for literal block (preserves newlines) and > for folded block (newlines become spaces). Useful for shell scripts in ConfigMaps.