YAML tools · 5 min read
JSON to YAML: making machine output readable again
JSON is excellent on the wire and unpleasant in a pull request. When an API response, a Terraform state fragment or a package manifest has to become something a human reviews line by line, a JSON to YAML conversion is the usual answer — and the details of how that conversion quotes and indents decide whether the result stays readable six months later.
Updated
Why convert JSON to YAML at all
The two formats hold identical data, but they optimise for different readers. JSON spends characters on braces, commas and quotes; YAML spends them on structure that the eye can follow as indentation. For data that is generated and consumed by programs, JSON wins. For data that a person edits — Helm values, CI definitions, Ansible inventories, Docker Compose files — YAML wins, which is why this direction comes up whenever generated data needs a human owner.
Comments are the one thing that cannot survive
The conversion can restore readability but it cannot restore intent: the source JSON had no comments to carry over. If your generated YAML will be maintained by people, add a short header comment describing where it came from and what regenerates it, so nobody edits a file that will be overwritten on the next deploy.
Quoting: where converted YAML quietly breaks
YAML treats several bare words as values rather than strings. A converter that drops quotes aggressively can change types without changing a single visible character:
country: NO # parses as boolean false in YAML 1.1
version: 1.10 # parses as the number 1.1
time: 22:30 # parses as a sexagesimal integer
name: "on" # quoted on purpose — must stay a string
Good output quotes any string that could be misread — `yes`/`no`/`on`/`off`, numeric-looking identifiers, values with leading zeros, times and dates — rather than quoting everything, which produces the wall of punctuation you were trying to escape.
Indentation and multi-line strings
Two spaces is the safe default: it is what Kubernetes documentation, Helm templates and most editors assume, and it survives copy-paste between tools. Deep nesting in four-space style gets hard to scan past about six levels. Long strings are the other formatting decision — a JSON value with embedded newlines can come out as an escaped one-liner or as a YAML block scalar that reads naturally. If the field is a shell script or a config snippet, ask for the block form.
Sorting keys makes diffs meaningful
JSON object key order is not significant, so converters are free to reorder. Sorting keys alphabetically makes regenerated files diff cleanly: without it, a changed deployment order shows up as a whole-file rewrite. If you are tracking generated YAML in git, sorting is the difference between a one-line diff and a two-hundred-line one.
Keep the round trip in one place
Because the two directions are inverses, it is worth having both in the same tool so you can convert, edit, and convert back without switching context or pasting your configuration into three different services. The browser-based converter on this site pairs with the YAML to JSON tool, works offline, and never uploads the payload — which matters when the JSON in question is a production API response.
JSON to YAML — frequently asked questions
Will converted YAML keep my key order?
Converters may sort keys or preserve insertion order. Sorting is usually the better choice for files tracked in git because regenerating produces stable, minimal diffs; preserve the original order when the ordering itself is meaningful to readers.
Why did a value change type after a JSON to YAML conversion?
Bare scalars in YAML are re-interpreted: `no`, `on` and `off` can become booleans, and values like `1.10` can become numbers. A safe converter quotes strings that would otherwise be misread. If a field must stay a string, quote it explicitly in the YAML.
Can I convert JSON to YAML offline?
Yes — the conversion is a local parse and re-serialise with no server involved, so the tool keeps working with the network disconnected and your data never leaves the browser tab.
Tools mentioned in this post
Keep reading
6 min read
YAML to JSON: converting configs without losing your mind
Convert YAML to JSON in the browser with multi-document support and exact error locations — plus the YAML mistakes that quietly break CI pipelines.
6 min read
JSON formatter: pretty, minified, and actually valid
A JSON formatter that pretty-prints, minifies and validates with exact error locations — plus the five syntax mistakes behind almost every invalid JSON error.
- Longer read: YAML vs JSON: When to Use Which (and How to Convert)