How to use YAML Formatter
- Paste the YAML.
- Choose indentation, collection style and quoting.
- Fix any reported error and copy the clean document.
YAML Formatter features
- Parses YAML 1.2 and reports syntax errors with line, column and excerpt
- Re-emits with 2 or 4-space indentation and consistent quoting
- Block or flow style for collections, optional key sorting
- Multi-document streams (---) are supported
- Detects duplicate keys and alias bombs
- Great for Kubernetes manifests, Docker Compose, GitHub Actions and OpenAPI files
YAML Formatter example
Normalise indentation
Input:
services:
web:
image: nginx
ports: [ "80:80" ]Output:
services:
web:
image: nginx
ports:
- "80:80"Frequently asked questions about YAML Formatter
Does it keep comments?
No. The document is parsed and re-emitted, so comments and anchors are resolved away. Use it for normalising indentation and quoting rather than for comment-heavy files.
What errors are reported?
Syntax errors with line and column, duplicate keys, bad indentation and unterminated quotes. The error excerpt shows the surrounding lines.
Can I format multi-document files?
Yes. Documents separated by --- are formatted individually and re-joined with --- separators.
Why did my "yes"/"no" or "1.0" values change?
They did not — the formatter emits values in the YAML 1.2 core schema, so strings that would otherwise be read as booleans or numbers are quoted to keep their type.
Technical notes
Formatting is parse-and-re-emit through the yaml package: parseAllDocuments runs in strict mode with uniqueKeys and merge enabled, then each document is normalised to JSON-safe values and printed again with lineWidth 0. Consequently anchors, aliases and << merge keys are expanded into plain copies, !!timestamp and !!binary become ISO 8601 and base64 strings, explicit tags are dropped, and integers above 2^53 − 1 are rounded. Under the 1.2 core schema, yes/no/on/off remain strings.
Because each document becomes a JavaScript object between parsing and printing, integer-like keys (0, 1, 42) are quoted and hoisted to the front in ascending order even with sorting off; 'Sort keys' then orders by UTF-16 code units, so uppercase precedes lowercase. Block sequences are indented under their parent key, multi-line strings become | literal blocks, 'Flow style' collapses a document onto one line, and streams are re-joined with --- (an empty document prints as null).