YAML Formatter
Paste messy YAML and get a consistently indented, cleanly quoted version back. The formatter validates as it goes, so it doubles as a linter: any syntax error is highlighted on the exact line.
Related tools
What the formatter changes
- Indentation is normalized to 2 or 4 spaces at every level, including list items nested inside mappings.
- Flow style collections such as
[a, b]and{k: v}are expanded into block style. - Quoting is minimized: strings are left bare when safe and double-quoted only when needed to preserve their type or special characters.
- Trailing whitespace and inconsistent blank lines are removed.
- Multi-document streams are kept, with each document separated by
---. - Key order is preserved unless you choose to sort keys.
Example
Input:
app: { name: yamlchecker, version: '2.1.0' }
server:
host: 0.0.0.0
port: 8080
features: [validator, formatter] Output with 2-space indent:
app:
name: yamlchecker
version: "2.1.0"
server:
host: 0.0.0.0
port: 8080
features:
- validator
- formatter When to use a YAML formatter
Formatting is most useful right before a code review or a commit. A consistent layout makes diffs smaller and easier to read, and running the file through a parser catches the indentation slips that YAML is famous for. If you only need to know whether a file is valid, the plain YAML validator is faster. To see how two versions of a file differ after formatting, use the YAML diff tool.
Frequently asked questions
Does the formatter keep my comments?
No. The formatter parses the YAML into data and writes it back out, and comments are not part of the data model, so they are removed. If you need to keep comments, use the YAML validator to check the file and fix indentation by hand.
Does it change key order?
Not unless you tick Sort keys. By default keys stay in the order you wrote them.
Can it convert tabs to spaces?
Tabs are not valid YAML indentation, so a file that uses them will fail to parse and the error line is highlighted. Replace the tabs with spaces (most editors can do this in one command) and the formatter will then normalize the indentation.
What does the formatter do with flow style like {a: 1, b: 2}?
Flow-style mappings and sequences are expanded into block style, one key or item per line, which is the conventional layout for configuration files.
Are anchors and aliases preserved?
Aliases are expanded so the output contains no & or * references. The data is identical, but if you rely on anchors to keep files short, review the output before replacing the original. Learn more in the anchors and aliases guide.