YAML Formatter

Reformat and normalise YAML indentation and quoting.

The YAML Formatter re-indents YAML so it follows one consistent style. Choose 2 or 4 space indentation and optionally tick Sort keys to put mapping keys in alphabetical order. The input must parse as valid YAML, so it also works as a quick syntax check.

What does formatting YAML do?

YAML represents structure with indentation, so formatting is more than cosmetics: the indentation is part of the syntax. This formatter parses the text and writes it out again with uniform indentation and consistent list style. That makes diffs smaller and files easier to read. Sorting keys puts mapping keys in alphabetical order at every level, which helps when comparing similar files but changes the order of the content, so use it deliberately. Lists keep their order. Because the document is rewritten, flow collections can be normalised, for example [1,2] becomes [ 1, 2 ]. Comments are kept when keys are not sorted but are lost when Sort keys is on, because sorting works on plain data.

How to use YAML Formatter

  1. Paste YAML Enter the YAML in the YAML pane.
  2. Choose the indent Select 2 spaces or 4 spaces.
  3. Decide on sorting Tick Sort keys if you want alphabetical key order.
  4. Review and copy The Formatted YAML pane updates automatically. Copy it or download formatted.yaml.

Frequently asked questions

Are comments preserved?

Yes when Sort keys is off. When it is on they are dropped, because sorting rebuilds the document from plain data.

Does sorting reorder list items?

No. Only mapping keys are sorted, at every level. Sequences keep their order.

Can formatting change the meaning of my YAML?

Not normally, since the same data is written back. Sorting changes the order of keys, and anchors and aliases are expanded when sorting, so review the result.

Why only 2 and 4 spaces?

They are the two common conventions. YAML allows other widths as long as they are consistent.

Can it format several documents in one file?

Yes, each --- document is formatted, but check the --- separators in the output, because without Sort keys a doubled separator can appear.

Is my data uploaded?

No. The conversion runs in the page and the text you enter is not sent anywhere.