Example: a Kubernetes ConfigMap
{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": {
"name": "app-config"
},
"data": {
"LOG_LEVEL": "info",
"ENABLE_CACHE": "on",
"COUNTRY": "NO",
"FILE_MODE": "0644",
"RELEASE": "1.10"
}
}
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
LOG_LEVEL: info
ENABLE_CACHE: "on"
COUNTRY: "NO"
FILE_MODE: "0644"
RELEASE: "1.10"
Every value under data must be a string for Kubernetes. Unquoted, on and
NO would be read as booleans by YAML 1.1 parsers, 0644 as the octal number 420, and
1.10 as the number 1.1. The converter quotes all four, while info needs no quotes.
JSON vs. YAML at a glance
| Feature | JSON | YAML |
|---|---|---|
| Comments | Not allowed | # comment |
| Structure | Braces and brackets | Indentation |
| Quotes | Always double quotes | Optional for most strings |
| Multi-line strings | Escaped \n | Block scalars | and > |
| Reuse | None | Anchors & and aliases * |
| Typical use | APIs, data exchange | Config files, CI/CD, Kubernetes |
Convert JSON to YAML on the command line
# yq (mikefarah/yq v4)
yq -P '.' config.json > config.yaml
# Python
python -c 'import sys, json, yaml; print(yaml.safe_dump(json.load(sys.stdin), sort_keys=False))' < config.json
Need the reverse? Use YAML to JSON. Working with Rust or Python packaging? Try JSON to TOML.
Frequently asked questions
How do I convert JSON to YAML?
Paste JSON into the tool above and the YAML appears instantly. Objects become indented key/value blocks, arrays become "- " lists, and strings are quoted only when needed. Use Download to save it as a .yaml file.
Is all JSON valid YAML?
Almost. YAML 1.2 is a superset of JSON, so you could paste JSON directly into most YAML files. Converting it to block-style YAML is still worth it: it is easier to read and diff, and it supports comments.
Why are some values like "no" or "0644" quoted?
In YAML 1.1, which is still used by PyYAML and many older tools, unquoted no, yes, on and off are booleans, 0644 is an octal number and 1.10 becomes the float 1.1. The converter quotes these strings so they stay strings in every parser. This is known as the "Norway problem", because the country code NO turned into false.
Can I convert JSON to YAML for Kubernetes or Docker Compose?
Yes. The output is standard YAML that kubectl, Helm and docker compose accept. Kubernetes ConfigMap and Secret values must be strings, which is exactly why the safe quoting matters there.
Does the converter keep key order?
Yes. Keys are written in the same order as in your JSON, so diffs against the original stay readable.