YAML to JSON converter (and back)
Paste YAML to get JSON, or paste JSON to get YAML. It converts both ways as you type, points at the exact line of any error, and runs entirely in your browser.
How to convert YAML to JSON
- Paste YAML on the left, or drop a
.yamlor.ymlfile. The JSON appears on the right as you type. - Going the other way? Paste JSON on the right and the YAML appears on the left.
- Fix errors fast: a syntax error names the line and column, such as a bad indent or a missing
]. - Copy or download the result, with JSON indented by 2 or 4 spaces, tabs, or minified.
What gets converted, and how
- YAML 1.2 rules are used, the version every modern parser follows. Comments are dropped, since JSON has none.
- Several documents separated by
---, as in Kubernetes manifests, become a JSON array with one item per document. - Anchors and aliases (
&baseand*base) are expanded into full copies. A file whose aliases would expand into millions of nodes (a "billion laughs" YAML bomb) is refused instead of freezing your browser. - Big integers such as IDs above 253 are kept exactly in both directions.
- Multi-line strings from JSON become YAML block literals (
|), so they stay readable.
The Norway problem
Older YAML 1.1 parsers, such as PyYAML, Ruby's Psych and many CI tools, read unquoted NO, yes, on and off as booleans, 0755 as an octal number and 1:30 as a number of seconds. So country: NO silently becomes country: false. When converting JSON to YAML, this tool quotes every string that a YAML 1.1 reader could misread, so the YAML means the same thing everywhere.
YAML and JSON in code
- JavaScript:
import YAML from "yaml"; YAML.parse(text)andYAML.stringify(obj) - Python:
yaml.safe_load(text)andyaml.safe_dump(obj, sort_keys=False)(neveryaml.loadon untrusted input) - Shell:
yq -o=json file.yamlandyq -P file.json - Go:
sigs.k8s.io/yamlwithyaml.YAMLToJSON(b)andyaml.JSONToYAML(b)
Questions
Is my YAML uploaded?
No. The conversion runs in your browser with the open-source yaml library, so config files with secrets never leave your device.
What happens to comments?
JSON has no comments, so YAML comments are dropped when converting to JSON. Converting back to YAML can't restore them.
How are multiple YAML documents handled?
A file with several documents separated by --- becomes a JSON array, one element per document, which is handy for Kubernetes manifests.
Why are some strings quoted in the YAML output?
Strings like NO, yes, on, 0755 or 2026-11-07 would be read as booleans, numbers or dates by YAML 1.1 parsers such as PyYAML. Quoting them keeps them strings for every reader.
Why does my YAML give a duplicate key error?
YAML requires keys in a mapping to be unique. Two identical keys at the same level are an error rather than the last one silently winning.
What about .inf and .nan?
YAML supports infinity and NaN but JSON doesn't, so they become null in the JSON and the tool tells you which values changed.
Is YAML a superset of JSON?
Almost: YAML 1.2 accepts nearly all JSON as valid YAML. That is why you can paste JSON into a YAML file, but converting it gives cleaner block-style YAML.