JSON to YAML Converter
runs in your browserConvert JSON to YAML and YAML back to JSON, with anchors resolved, multi-document streams handled and a warning for values JSON cannot hold.
JSON
YAML
about this tool
Both directions
Convert JSON to YAML or YAML back to JSON with the same tool — swap the direction and the panels change places. The two formats describe the same data model, so a round trip is lossless in almost every case, and the exceptions are reported rather than guessed at.
Why convert at all
YAML is what configuration is written in: Kubernetes manifests, CI pipelines, Docker Compose, Ansible. JSON is what APIs and programs speak. So the conversion usually happens at the boundary between the two — you have an API response and need it as config, or you have a manifest and need to send it somewhere that only accepts JSON.
YAML is also considerably easier to read for anything nested, which makes the conversion useful purely as a way of understanding an unwieldy JSON document.
Values YAML has and JSON does not
Going from YAML to JSON is where data can be lost, because YAML is the richer
format of the two. It can write .nan and .inf, it can hold integers larger
than JSON's numbers safely carry, and it distinguishes an explicit null from a
missing key. JSON.stringify turns all of that into null without comment, so
the tool reports each one with its path instead of losing it quietly.
A YAML file containing several documents separated by --- also has no direct
JSON equivalent. Those are combined into a JSON array, and you are told that it
happened rather than being handed the first document alone.
The YAML traps worth knowing
YAML is a much larger specification than JSON, and most of its surprises come from its willingness to guess types:
noandoffbecome false in YAML 1.1 parsers. The Norwegian country codeNOhas broken real deployments this way. Quote it.- A leading zero can mean octal, so
0755may not be the number you meant. 1.0is a number and1.0.0is a string, which bites version fields.- Tabs are illegal as indentation. YAML permits only spaces, and an editor that helpfully inserts a tab produces a parse error with a confusing message.
22:30may parse as a sexagesimal number rather than a time.
Converting from JSON avoids all of these, because everything arrives already typed and gets quoted where it needs to be.
TOML was designed as a reaction to exactly this list, which is why it has been gaining ground for configuration files.
Sorting and indentation
Sort keys orders every mapping alphabetically at every level, which is the easiest way to make two config files comparable. Indentation can be two or four spaces to match the house style of the repository you are pasting into.
Local processing
Both directions parse in the page. Config files are exactly the kind of thing that carries hostnames, bucket names and occasionally a secret, so none of it leaves your browser.
questions
- Is converting between JSON and YAML lossless?
- From JSON to YAML, effectively yes. From YAML to JSON it can lose data, because YAML can express .nan, .inf and very large integers that JSON cannot. Those are reported with their paths rather than silently turned into null.
- Why did my YAML value 'no' become false?
- Because YAML 1.1 parsers read no, off, yes and on as booleans. The Norwegian country code NO has broken real deployments this way. Quote the value to keep it a string; converting from JSON avoids the problem entirely.
- Why does my YAML file fail to parse?
- Most often a tab character used for indentation, which YAML forbids — only spaces are permitted, and the resulting error message is rarely clear about it. Inconsistent indentation depth is the next most common cause.
- What happens to a YAML file with multiple documents?
- Documents separated by --- are combined into a JSON array, and you are told that it happened, rather than being handed only the first document.
- Can I sort the keys?
- Yes, sort keys orders every mapping alphabetically at every level of nesting, which is the quickest way to make two config files comparable by eye.