YAML Formatter
Validate and re-indent YAML with 2 or 4 spaces in your browser. Syntax errors show the line and column. Nothing is uploaded.
Comments (# …) are removed: the formatter rewrites the data, it does not keep the original text.
How to use the YAML formatter
- Paste your YAML into the Input box, or write it directly there.
- Choose the Indentation: 2 spaces or 4 spaces.
- Click Format to re-indent the document. The result appears in Output.
- Click Validate to check the syntax only. The output is left unchanged. If the text holds several YAML documents, the message also tells you how many there are.
- If there is a mistake, the message gives its line and column, followed by the reason, such as a duplicated key or an indentation problem.
- Click Copy, or Download the result as
formatted.yaml.
Changing the indentation after a format run formats the text again with the new value.
What the formatter keeps and what it rewrites
The formatter reads the YAML with a parser and writes it again, using the indentation you chose. It uses the same YAML 1.2 core schema as the JSON to YAML converter, so yes and no stay as text, dates such as 2020-01-01 are written back as they were, and long lines are not folded onto several lines.
Because the output is rewritten from the data, the formatter does not keep the original text. Here is what changes:
- Comments are removed. Every line starting with
#and every comment at the end of a line disappears. Keep your annotated original file and format a copy if you need the comments. - Anchors and aliases are renumbered. A value reused with
&and*is written with generated anchor names such as&ref_0. - Merge keys are expanded. A
<<: *baseline is replaced by the keys it brings in. - Empty values become
null. Both~and an empty value after a colon are written asnull. - Literal blocks keep their style. A multi-line text written with
|stays a|block.
The data stays the same, so the formatted document reads back to the same values.
Validation and its limits
Validation catches syntax errors, indentation errors, duplicated keys in one mapping, and alias bombs: a document whose aliases expand to more than a million values is refused. It does not check the content against a schema. A file that is valid YAML can still be a wrong Kubernetes manifest or GitHub Actions workflow, so use the schema checker of your platform for that step.
Choosing 2 or 4 spaces
Two spaces is the most common style in configuration files, and it keeps nested lists short. Four spaces can make deep documents easier to read for some teams. Pick the style your project already uses, because a consistent indentation matters more than the number.
Frequently asked questions
Why are my comments gone after formatting?
The formatter rebuilds the document from its data, and the parser does not keep comments. This is a limit of the parsing library, not something the tool can switch on. Keep the original file if the comments matter.
Does formatting change what my YAML means?
It should not change the values. Comments, the original spacing and the choice between equivalent spellings are the parts that change. A ~ and an empty value both become null, which means the same thing to a YAML parser.
Why does my YAML look correct but show an error?
The most common causes are a tab used for indentation (YAML only accepts spaces), a missing space after a colon, a list item that is not indented under its key, or a key written twice. The error line points to the place where the parser got lost, which is often just after the real mistake.
Does this check a Kubernetes or GitHub Actions file against its schema?
No. The tool checks that the text is valid YAML and rewrites it. Field names, required values and types are not checked against the schema of a particular product.
Is my YAML uploaded?
No. Parsing and formatting run in your browser, and the text you paste is never sent to a server.
Related tools
- JSON to YAML Converter Convert JSON to YAML and YAML to JSON in your browser, with anchors, merge keys and multi-document files supported. Nothing is uploaded.
- JSON Formatter and Validator Free JSON formatter and validator that beautifies, minifies and checks JSON in your browser, with syntax errors reported by line and column.
- Text Diff Checker Compare two texts and see every difference side by side or inline, by line, word or character. Private diff checker that runs in your browser.