YAML Formatter & Prettifier — Beautify YAML Documents Online
What YAML Formatter does
YAML Formatter expands flow collections into readable block style and applies either two-space or four-space indentation. It keeps comments, quoted strings, anchors, and aliases in the document. Small edits format after a short pause; for inputs over 1 MB, choose Run so a paste does not trigger a long parse. Use it to review configuration structure before applying a change.
Worked examples
Expand a compact service mapping
A service configuration was written with braces and brackets, making its nested port list difficult to scan. Paste it with the default two-space indent.
Input
# web service
service: {name: api, ports: [8080, 8081]}
Output
# web service
service:
name: api
ports:
- 8080
- 8081
The full-line comment stays at the top. The flow mapping becomes an indented mapping and the flow sequence becomes one item per line. The scalar values themselves remain api, 8080, and 8081. This is useful when reviewing a deployment change because each port gets its own visible line. The formatter does not decide whether the ports are valid for a particular application; it only rewrites the YAML representation.
Preserve an anchor and merge reference
A configuration shares default values through an anchor and overrides one field for a worker. Formatting should keep that relationship visible rather than expanding it into unrelated copies.
Input
defaults: &base
retries: 3
timeout: 10
worker:
<<: *base
timeout: 20
Output
defaults: &base
retries: 3
timeout: 10
worker:
<<: *base
timeout: 20
The source is already in block style, so the output text is unchanged. The &base anchor remains attached to defaults and the *base alias remains on the merge key under worker. That matters because a reviewer can still see where inherited values originate. A downstream YAML processor may interpret the merge key according to its own schema or version; use the target application’s parser to confirm the resolved configuration.
What to check before using the output
Formatting is not application validation
A document can be well-formed YAML and still be an invalid Kubernetes manifest, Compose file, or application configuration. This tool reports parser errors, but it has no knowledge of your deployment schema. After formatting, validate with the actual application or a schema-aware checker. Review a multi-document file resource by resource so a syntactically correct stream does not hide a wrong kind or missing required field.
Implicit scalar types vary by parser
YAML 1.1 interprets plain words such as yes, no, on, and off as booleans. YAML 1.2 generally treats them as strings. If a value must remain text across older tools, quote it explicitly in the source. The formatter preserves existing quoted strings; it cannot force every downstream parser to use the same schema. Pay particular attention to country codes, feature flags, and identifiers with leading zeroes.
country: "NO"
enabled: "yes"Anchors are part of the document structure
An alias can refer back to an earlier anchor, and a merge key can create inherited mapping entries. The formatter keeps the visible anchor and alias in the worked example, but it does not display the fully resolved object. If you need the parsed values, convert a representative document to JSON and compare it with what your target parser produces. Avoid editing anchor names without checking every reference.
Large inputs use an explicit Run step
For a document over 1 MB, the input editor switches to a plain-text model and waits for Run. Parsing and formatting happen in a worker, so typing and navigation stay separate from the transform. A very large or deeply nested document can still take time and memory inside that worker. Clear cancels the active job; after changing an input, press Run again to get a result for the latest text.
How to Use the Tool
- Paste your YAML document into the input editor.
- Small inputs format as you type. Choose Run for inputs over 1 MB.
- The output preserves all data values and comments (comments are maintained if present in input).
- Download the formatted YAML or copy it for your config file, manifest, or playbook.
Key Features & Specifications
- Formats both block and flow style YAML
- Configurable indentation: 2-space (Kubernetes standard) or 4-space
- Removes trailing whitespace and normalizes blank lines between sections
- Preserves YAML comments during formatting
- Validates YAML syntax before formatting to prevent corrupting invalid documents
Frequently Asked Questions (FAQ)
- Q:Will a flow mapping become block style?
- Yes. The formatter uses the YAML document API with block collection style, so a compact mapping and sequence expand into indented lines.
- Q:Are comments and anchors kept?
- The formatter keeps comments and the anchor and alias syntax in the examples shown here. Review unusual directives or custom tags with the parser used by your application.
- Q:Why does a large paste wait for Run?
- Inputs over 1 MB are not formatted automatically. The editor stays responsive while you choose when to send the current text to a background worker.
- Q:Can this tool prove a manifest will deploy?
- No. It checks YAML parsing and rewrites layout. Your deployment system must validate resource types, required fields, and application rules.