JSON Beautifier
Guide · 5 min read

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.

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.

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.

Convert JSON to YAML Now

Free, instant, and works entirely in your browser.

Open JSON to YAML

Related Guides