YAML Formatter
Parse-and-reemit YAML formatting with selectable indent; errors point at line and column.
YAML readability rests on indentation discipline, and YAML from multiple sources — different editors, different authors, copy-paste — always fights: two-space against four, list items misaligned with keys, tabs smuggled in among spaces. This tool parses with js-yaml and re-emits in one consistent style: indent width selectable, quoting and line-wrap conventions normalized, anchors expanded to literals.
Failures report with line and column — YAML's native errors are famously cryptic ("could not find expected ':'"), and the position at least lands you on the offending line. A successful parse doubles as validation: if it formatted, it was valid YAML.
Why parse-and-reemit instead of character-level reindent
In YAML, indentation IS syntax: nudging it character-by-character changes meaning — one space turns a list into a map. Only parsing into data and re-emitting makes indentation a pure function of structure, guaranteeing no semantic drift. The cost is comments, which the round trip does not preserve.
Tabs are YAML's natural enemy
The spec forbids tab indentation outright — tabs cannot align consistently across display widths. YAML copied from PDFs, Word or chat apps frequently carries tabs; this page flags them in the error, and formatted output is always spaces.
Frequently asked questions
- Does formatting lose comments?
- Yes. The parse-and-reemit route cannot carry comments (the parser does not record their positions). It is a deliberate trade of "semantics preserved" against "comments kept" — for comment preservation use an editor plugin.
- Are multi-document streams (---) supported?
- No — they report an error. Multi-doc streams are rare in config files; split on --- and process section by section.
- Can I convert YAML to JSON?
- Yes — use the JSON converter pages (YAML → JSON direction), which share the same parser as this page.