YAML Formatter
Re-indent and beautify YAML with consistent two-space nesting
YAML Input
Formatted YAML
No commentsWhat is a YAML Formatter?
YAML puts all its meaning in whitespace, which is great until a file has been edited by four people with four different editor configs. You end up with a manifest indented three spaces in one block and five in the next, list items that hang at odd offsets, and a review diff full of noise that has nothing to do with the change. This page takes whatever you paste and writes it back out with consistent two-space indentation, one style throughout.
Formatting is a full round trip: your text is parsed into a plain value, and that value is written out again with two-space indentation, a 100-column wrap and no anchors. If you want nearly the same output from a Node script, those are the indent: 2, lineWidth: 100 and noRefs: true options of js-yaml's dump(). The one difference is numbers: a plain dump() writes price: 14.50 back as 14.5, and this page writes every number with the digits you typed. That round trip is why the formatting is genuinely uniform: the output is generated fresh from the data rather than patched in place. It also parses to the YAML 1.2 core schema, so what you see is what a modern parser sees.
The same round trip is why comments do not survive. A parse keeps no record of them (they exist in the text, not in the data) so the formatted output has none. It also normalises quoting ('internet' becomes internet) and expands anchors and aliases into duplicated blocks. If your YAML is documented with # notes, treat this tool as a way to inspect and tidy a copy, not as a replacement for the file in your repo. There is no setting that changes this; preserving comments requires a parser that keeps a concrete syntax tree, and this formatter does not work that way.
Everything runs in the browser tab. Nothing is uploaded, cached, or logged, which matters here more than on most pages, because YAML is exactly where registry credentials, database passwords, and API tokens tend to live.
How to Format YAML
- Paste or Upload Your YAML – Paste the messy manifest, playbook or compose file on the left. Upload takes a
.yamlor.ymlfrom disk, but it parses the file first and refuses one that does not load, so paste a broken file by hand to see the error line. - Read the Output as It Appears – Nothing to click. Each keystroke restarts a 300 ms timer, and when it runs out the whole document goes through load and dump again. Fix an indentation error on the left and the red message on the right gives way to formatted output once you have paused for 300 ms.
- Check What Changed Besides Indentation – Scan for missing
#comments, quotes that were dropped, and anchors that were expanded into repeated blocks. All three are expected; none of them are recoverable from the output. - Fix Errors Using the Reported Line – A broken document produces a message like
Invalid YAML (line 12, column 5): bad indentation of a mapping entry. Count to that line in the left editor: the cause is almost always there or one line above. - Take the Result With You – Copy is for pasting into a pull request or a ticket; Download writes
formatted.yamlto disk. Before either one replaces a file in your repo, diff the two versions, so losing the comments is something you chose.
Pro Tip: Point your editor at the file instead when comments matter. Set "editor.insertSpaces": true and "editor.tabSize": 2 for YAML and you get consistent indentation while you type, with every comment intact. Use this page for the files you did not write: a config someone pasted into a ticket, a generated manifest, a snippet from a wiki.
Example
A subscriber provisioning file with drifting indentation. On the right, the same document at a uniform two spaces, and note what else moved: the two # comments are gone, and 'Unlimited 5G' lost its now-unnecessary quotes. The quoted "NO" and "1.20" keep their quotes, because dropping them would change their type.
# provisioning defaults subscriber: msisdn: "447700900142" plan: 'Unlimited 5G' roaming: true country: "NO" # keep Norway firmware: "1.20" radio: cellId: 21453 rsrp: -92
subscriber: msisdn: '447700900142' plan: Unlimited 5G roaming: true country: 'NO' firmware: '1.20' radio: cellId: 21453 rsrp: -92
Read This Before You Overwrite Anything
Comments are the main reason teams pick YAML over JSON. The # leave qci at 9 until the core upgrade line next to a value is often the only place that decision is written down. A load/dump round trip deletes every one of them, and no amount of care on your side changes that: the parser hands back data, and data has no comments attached.
So the safe workflow is: format a copy, read it, fix what the reformatting revealed, and apply that fix to the original file by hand. What is genuinely lost if you paste the output over your source: every # comment including the license header; deliberate quoting styles such as single quotes or block scalars where a plain scalar would do; and anchors and aliases, which are expanded so that one shared block becomes five identical copies. Key order survives, the formatter dumps with sortKeys: false, but blank lines used to visually group related keys do not; the output packs everything together with no gaps.
If a note has to survive machine processing, promote it to a real key: _note: "keep qci at 9 until the core upgrade" is data, and data round-trips fine. And if you need true comment-preserving reformatting, you need a library that keeps a concrete syntax tree, such as eemeli's yaml package, or your editor's own YAML formatter, which edits the text in place instead of regenerating it.
YAML Gotchas Worth Knowing
Tabs Are Illegal for Indentation
Not discouraged: illegal. The spec forbids tab characters in indentation, and every conformant parser rejects them. The cruel part is that a tab-indented file looks perfectly aligned in your editor, so you stare at correct-looking YAML while the parser insists it is broken. This page checks for a leading tab before parsing and tells you the exact line, instead of leaving you with a confusing "bad indentation" error two lines later. Fix it by configuring your editor to expand tabs to spaces for .yaml and .yml.
Indentation Is the Syntax
In JSON, braces define structure and whitespace is decoration. In YAML the whitespace is the structure, so a single extra space moves a key from one parent to another and the file still parses: it just means something different. That is the dangerous class of bug: not a crash, but a value silently attached to the wrong block. Formatting helps because once everything is at a uniform two spaces, a key sitting at the wrong depth is visible at a glance. Also note that list items may sit at the same column as their parent key, which trips people up but is perfectly legal.
The Norway Problem: country: NO
Norway's ISO 3166 code is NO, and under YAML 1.1 rules NO, yes, off and friends are booleans, so a 1.1 parser reads country: NO as false. This page loads it with the 1.2 core schema, where it is just a string, and then does something worth noticing: paste country: NO here and the output reads country: 'NO'. The dumper adds the quotes on purpose, because it knows PyYAML, Ruby's Psych and older Go libraries would otherwise turn the formatted file into a boolean. The same happens to an unquoted enabled: yes, which comes back as 'yes'; if you meant a boolean, write true.
Numbers Keep the Digits You Typed
Most load-and-dump formatters quietly respell numbers: version: 1.20 comes back as 1.2, price: 14.50 as 14.5, zip: 02134 as 2134. This one writes each number back exactly as it appears in your file, and a 19-digit iccid: 8944500102030405060 keeps every digit instead of being rounded at JavaScript's 253 ceiling. That only protects the text, though. To any YAML loader an unquoted 1.20 is still the float 1.2 and 02134 is still the integer 2134, so the program that reads the file next sees a different release and a ZIP code with no leading zero. Quote versions, ZIP codes and IDs with leading zeros; YAML to JSON shows you what a program will actually receive.
YAML Is a Superset of JSON
Any valid JSON document is already valid YAML 1.2, so you can paste JSON into the left panel and this formatter will happily turn it into block-style YAML. Handy when you want to read an API response with fewer braces, or when you are not sure which format a snippet is. It also explains why so many tools accept one --values flag for both. Going the other way is not symmetric: YAML has comments, anchors, multi-document streams, and non-string keys, none of which JSON can express, see YAML to JSON for what that costs.
Common Use Cases
Cleaning Up a Kubernetes Manifest
Manifests accumulate mixed indentation faster than most files because they get copied out of blog posts, generated by templates, and hand-edited under pressure. Formatting one gives you a single consistent style, so the next diff shows only what actually changed. Do it on a copy: the # owned by the payments team line above a namespace is exactly the kind of comment you do not want to silently delete. The Kubernetes object docs explain the fields once the shape is readable.
Making Sense of a Pasted Config
Someone drops a snippet into a ticket and the indentation has been mangled by the chat client. Rather than fixing it by eye, paste it here, if it parses, you get a clean version and you know the structure is sound; if it does not, you get a line number to argue about. This is where the formatter earns its keep, because a snippet from a ticket has no comments worth protecting.
Reviewing a CI Pipeline Before It Runs
A GitHub Actions or GitLab CI file that fails to parse costs you a full push-and-wait cycle to find out. Formatting it locally is a two-second check that the document is well formed and that every step sits at the depth you meant. If two versions need comparing, format both the same way first, then an online text comparison tool shows real changes instead of whitespace noise.
Normalising Files Before a Diff
Two configs that behave identically can diff badly because one uses four-space indentation and quotes every string. Run both through the formatter and the diff collapses to the handful of lines that genuinely differ. Just remember both outputs are comment-free, so use them for reading, not for committing.
Key Features
- Consistent Two-Space Indentation – Output is regenerated with
indent: 2, so nesting depth is uniform from the first line to the last. - Honest About Comment Loss – The notice sits above the editor, not buried in an FAQ, because pasting the output over a documented config is a real way to lose work.
- Tab Detection – Indent with a hard tab and you get a message naming the line, instead of a cryptic indentation complaint from the parser.
- Real Line and Column Numbers – YAML parse errors count lines and columns from 0; this page adds one before showing them, so the number matches your editor's gutter.
- Anchors Expanded, References Resolved –
noRefs: truemeans the output has no&anchor/*aliasindirection to chase while reading. - Runs Entirely in Your Browser – No upload, no server, no logging. Safe for files that contain secrets.
Frequently Asked Questions
Why did the formatter delete my comments?
Because formatting is a round trip: yaml.load() converts your text into plain data, and yaml.dump() writes new text from that data. Comments live in the text, not in the data, so they are gone by the time the output is written. That comes from the round trip itself, not from a setting, so there is no flag to turn on. Keep the original file and apply fixes to it by hand, or use a comment-preserving library such as yaml if you need reformatting in an automated pipeline.
What else changes besides indentation?
Three things. Quoting is normalised: unnecessary quotes are dropped and quotes are added where a plain scalar would be ambiguous. Anchors and aliases are expanded, so a block shared five times becomes five copies. And blank lines used for visual grouping disappear. Key order is preserved (sortKeys: false), and no value is changed: a string stays a string, a number stays a number.
Why does my file fail with a tab error?
YAML forbids tab characters in indentation, full stop. Any editor configured to insert a hard tab will produce a file that looks correctly aligned and refuses to parse in every conformant tool. This page checks the leading whitespace of each line before parsing and names the first offending line, because the parser's own message often points somewhere else. Tabs inside a value are fine; it is only indentation that is illegal.
Does formatting change my values?
No. Strings stay strings, numbers stay numbers, and numbers keep their spelling: 14.50, 1e3, 0x1F and 02134 come out exactly as they went in. What the formatter cannot do is change what YAML already decided about your text. An unquoted 1.20 is a float, so the app that loads this file reads 1.2 whichever way the line is indented. If you meant a string, quote it in the source.
Can I format multi-document YAML?
Not in one pass, and it will not quietly format only the first document either. The loader here accepts exactly one document, so a second --- stops it and the right panel says the stream held more than one, with no line number attached because the error is about the file as a whole. Kubernetes bundles and helm template output are where this bites. Cut the file at each separator, format the pieces separately, and rejoin them with --- lines by hand. If all you need is proof that every document parses, the YAML Validator reads the whole stream with loadAll.
Is JSON accepted as input?
Yes, because YAML 1.2 was designed to accept JSON text as it stands. Paste {"imsi":"234150999912345","apn":"internet","qci":9} and you get three block-style lines back: imsi: '234150999912345', apn: internet and qci: 9. Note the single quotes the IMSI picked up; without them the digits would read back as a number. For the deliberate conversion with its own page and options, see JSON to YAML.
Why is the line number in the error one off from what js-yaml prints?
It is not: it is corrected. YAMLException.mark.line and .column are both 0-based, so the raw values are one lower than your editor's gutter. This page adds one to each before displaying, so the number you read is the number you scroll to.
Can I format a values file that holds passwords?
Yes. The load and the dump both happen in this tab, and unlike the table pages there is no share link to create here, so your text stays put; Copy and Download only touch your own clipboard and disk. Worth checking on any YAML tool, because Helm values files and Ansible vars are where database passwords and registry tokens usually sit.
What indentation does the output use?
Two spaces per level, which is the community convention and what Kubernetes, GitHub Actions, and Docker Compose examples all use. Lines wrap at 100 characters. If your team standardises on four spaces, format here for readability and re-indent in your editor before committing.
Related Tools
Useful Resources
- YAML Multiline Strings – A visual cheatsheet for the pipe, folded, and chomping indicators.
Comments are removed.Formatting parses your YAML into data and writes it back out, so every
#comment is dropped, quoting is normalised, and anchors are expanded into full copies. Keep your original file: copy the output only when you are sure you do not need the comments.