Many tools generate JSON, but the files people edit by hand are increasingly YAML: Kubernetes manifests, Docker Compose files, GitHub Actions and GitLab CI pipelines, Ansible playbooks, OpenAPI specs. You might have a JSON output from kubectl get -o json, an API response you want to turn into a fixture, or an old config.json that the team would rather maintain in a friendlier format.
This guide explains how JSON structures map to YAML, why a converter sometimes wraps values in quotes you did not expect, the indentation rules that make YAML both readable and fragile, and how to convert and check the result.
JSON and YAML describe the same data
YAML 1.2 was designed so that any valid JSON document is also valid YAML. The two formats describe the same building blocks, just with different syntax:
| Concept | JSON | YAML |
|---|---|---|
| Object / map | {"name": "web"} |
name: web |
| Array / list | ["a", "b"] |
- a and - b on separate lines |
| Nesting | braces and brackets | indentation |
| String | always double-quoted | usually unquoted |
| Comments | not allowed | # like this |
| Multi-line text | \n escapes |
literal or folded block scalars |
Because YAML relies on indentation rather than brackets, the same Kubernetes deployment is noticeably shorter and easier to scan:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
template:
spec:
containers:
- name: nginx
image: nginx:1.27
ports:
- containerPort: 80
The trade-off is that whitespace now carries meaning. One space too few or too many changes the structure, and tabs are not allowed for indentation at all.
Why some values come out quoted
YAML reads unquoted values and guesses their type. That convenience creates traps, so a careful converter quotes any string that would otherwise be read as something else:
version: '1.10' # unquoted, 1.10 would become the number 1.1
zip: '02134' # could lose its leading zero
enabled: 'yes' # older YAML 1.1 parsers read yes/no as booleans
country: 'NO' # the "Norway problem": NO read as false by YAML 1.1 tools
time: '12:30' # YAML 1.1 can read this as a base-60 number
pattern: '*.log' # a leading * means an alias in YAML
These quotes are not noise. Removing them can silently change your configuration: a version string becomes a float, a country code becomes false. When you hand-edit converted YAML, leave them in place. Genuine numbers and booleans from the JSON ("replicas": 3, "enabled": true) stay unquoted, because they are meant to be typed values.
Convert JSON to YAML with our tool
The JSON to YAML Converter uses the widely used js-yaml library and runs in your browser.
- Open the JSON to YAML Converter. Paste JSON into JSON input, or click Open file to load a
.jsonfile. Load sample shows a Kubernetes deployment. - Choose YAML indent: 2 spaces (the convention for Kubernetes, Compose and most CI systems) or 4 spaces.
- Turn on Sort keys A–Z if you want keys alphabetised at every level, which makes two files easier to compare. Leave it off to keep the original order, which usually matters for readability (
apiVersionandkindfirst). - Turn on Wrap long strings at 80 to fold very long text values across lines. By default long strings stay on one line.
- Review the YAML output, then Copy it or Download it as a
.yamlfile.
Lists are written with a dash, indented under their parent key, and multi-line strings become readable | block scalars instead of \n escapes. If the JSON is invalid, the output pane shows the error with its line and column instead of YAML. Fix it there, or use the JSON Formatter first to see the structure.
Other ways to convert
yq
The yq command-line tool (there are two popular projects with this name, with slightly different syntax) converts between formats. With the Go version, for example:
yq -p json -o yaml config.json > config.yaml
It is the best option in scripts and pipelines.
Python
import json, yaml # PyYAML
data = json.load(open("config.json"))
print(yaml.safe_dump(data, sort_keys=False, allow_unicode=True))
Pass sort_keys=False; PyYAML sorts keys by default.
Kubernetes itself
kubectl get deployment web -o yaml outputs YAML directly, so there is no need to fetch JSON and convert it. Remember to remove server-generated fields such as status, uid and resourceVersion before reusing a manifest.
Tips and pitfalls
Comments are not part of the data
JSON cannot hold comments, so converted YAML has none. Add them after converting. Be aware that converting YAML back to JSON, and then to YAML again, will remove any comments you added.
Keep indentation consistent
Pick 2 spaces and stick to it. Configure your editor to insert spaces when you press Tab in YAML files. The YAML Formatter can re-indent a file that has become inconsistent after manual edits.
Validate before you deploy
After editing converted YAML by hand, convert it back with the YAML to JSON Converter to confirm it parses and has the structure you expect. For Kubernetes, kubectl apply --dry-run=client -f file.yaml checks the manifest against the API types without changing the cluster.
Consider TOML for small app configs
If the config is flat and edited by humans, TOML is another option with fewer indentation traps. The JSON to TOML converter produces it from the same JSON.
Frequently asked questions
Is JSON valid YAML?
Yes, for practical purposes. YAML 1.2 is a superset of JSON, so a YAML 1.2 parser can read JSON files directly. Converting simply makes the file more readable.
Why does the converter put quotes around some strings?
To stop YAML from reading them as another type. Strings like 1.10, 02134, yes, NO or 12:30 would be interpreted as numbers or booleans by some parsers if left unquoted.
Should YAML use 2 or 4 spaces?
Both are valid. Two spaces is the norm for Kubernetes, Docker Compose, GitHub Actions and most CI tools, so choose it unless your project already uses four.
Can I use tabs in YAML?
No. The YAML specification forbids tabs for indentation. Tabs inside quoted strings are fine.
Does converting change the order of keys?
No, unless you turn on Sort keys A–Z. The converter keeps the key order from your JSON.