JSON to YAML Converter
Convert JSON to YAML and YAML back to JSON, with validation in both directions and a warning whenever the conversion cannot be lossless.
Runs entirely in your browser — which matters when the file is a Kubernetes manifest.
YAML
Converted. 292 B of JSON became 220 B of YAML.
name: devbox-tools
replicas: 2
image:
repository: ghcr.io/example/app
tag: 1.4.0
env:
- name: LOG_LEVEL
value: info
- name: REGION
value: eu-central-1
resources:
limits:
cpu: 500m
memory: 512Mi
How the two formats relate
YAML 1.2 is a strict superset of JSON: every valid JSON document is already valid YAML, which is why you can paste JSON into the YAML side of this tool and it works. The reverse is not true.
| Feature | JSON | YAML |
|---|---|---|
| Comments | No | Yes, with # |
| Multiple documents per file | No | Yes, separated by --- |
| Anchors and aliases | No | Yes — &name and *name |
| Non-string keys | No | Yes |
| Structural whitespace | No | Yes — indentation is the syntax |
| Trailing commas | No | Not applicable |
So: JSON → YAML is always safe. YAML → JSON is safe only if the YAML avoids the features in that list. This tool flags each one it finds.
The YAML traps worth knowing
The Norway problem
Under YAML 1.1 — which PyYAML and several other widely-used parsers still implement — these bare words are booleans:
countries:
- NO # false under YAML 1.1
- SE # the string "SE"
enabled: on # true under YAML 1.1, the string "on" under 1.2YAML 1.2 core, used by this tool, treats them all as strings. Since you often cannot control which parser reads your file, quote anything that could be misread: "NO", "on".
Version numbers become numbers
version: 1.10 # the number 1.1, not the string "1.10"
version: "1.10" # correctThe trailing zero is lost because 1.10 parses as a float. Always quote version numbers.
Colons inside values
title: Release: v2 # error — YAML sees a nested key
title: "Release: v2" # correctTabs are illegal
YAML forbids tabs for indentation outright. Since editors often insert them invisibly, this is a common cause of a file that looks correct and will not parse.
Converting on the command line
# yq — the usual choice
yq -P '.' file.json # JSON to YAML
yq -o=json '.' file.yaml # YAML to JSON
# Python, with PyYAML installed
python -c 'import json,sys,yaml; print(yaml.safe_dump(json.load(sys.stdin), sort_keys=False))' < file.json
python -c 'import json,sys,yaml; print(json.dumps(yaml.safe_load(sys.stdin), indent=2))' < file.yamlNote sort_keys=False — PyYAML sorts keys alphabetically by default, which makes the diff on a config file useless. This tool preserves key order for the same reason.
Frequently asked questions
Does the conversion lose anything?
JSON to YAML never loses anything, because YAML 1.2 is a strict superset of JSON. The other direction can: YAML has anchors and aliases, merge keys, multiple documents in one file, comments, and non-string keys, none of which JSON has. This tool warns you when the input uses any of them rather than silently dropping them.
Why did my YAML "no" become false somewhere else?
The Norway problem. Under YAML 1.1 — still used by PyYAML and older parsers — the bare words yes, no, on, off, y and n are booleans, so the country code NO becomes false. YAML 1.2 core, used here, treats them as strings. The safe move either way is to quote them: "no".
What happens to comments in my YAML?
They are lost. JSON has no comment syntax, so there is nowhere for them to go. This is the main reason a YAML config file cannot be round-tripped through JSON and back without losing something a human wrote.
Why does my YAML fail to parse when it looks fine?
Almost always indentation. YAML uses it structurally, so one extra space changes which mapping a key belongs to. Tabs are rejected outright. And a value containing a colon followed by a space needs quoting, because YAML reads it as a nested key.
What about duplicate keys?
This tool rejects them. Both JSON and YAML technically permit duplicate keys and most parsers silently keep the last one, which in a config file is a bug worth seeing rather than inheriting.
Is my data uploaded?
No. Both directions run entirely in your browser. That matters here more than for most converters, because the YAML people need to convert is usually a Kubernetes manifest, a CI pipeline, or an Ansible playbook — files that routinely contain infrastructure detail and occasionally secrets.
Related tools
- DataJSON Formatter and Validator
Prettify, minify and validate JSON — with the exact line and column of any error.
- TextRegex Tester
Test a pattern against your text and get a plain-English explanation of what it does.
- TimeCron Expression Generator and Parser
Build a schedule visually, or paste one and read it in plain English with the next run times.
- GuideHow to fix JSON parse errors
Each parser message translated into the actual problem, with the fix.
Need to inspect the JSON itself? The JSON formatter adds a tree view, key sorting and byte-level statistics.