YAML Formatter
DataFormat and validate YAML instantly in your browser. Catch syntax errors, normalise indentation, and produce clean output — nothing is ever uploaded anywhere.
What is a YAML?
The YAML Formatter parses raw or inconsistently indented YAML and produces a clean, consistently indented document with normalised structure. It uses a full, specification-compliant YAML parser — not a regex-based approach — which means it validates the input as it formats and returns a meaningful error message if the YAML is syntactically invalid.
YAML (YAML Ain't Markup Language) is the dominant format for developer configuration files. Docker Compose, Kubernetes, GitHub Actions, Ansible, Rails, and dozens of other tools use YAML for their configuration. It is human-friendly by design — indentation conveys structure, comments are supported, and strings do not need quotes in most cases. But this flexibility also makes YAML easy to break: a single misaligned indent or an extra tab character can produce a cryptic parse error.
Formatting YAML by hand is tedious and error-prone. When you paste a YAML snippet from documentation, a colleague's message, or an AI tool, the indentation may be inconsistent — mixing 2-space and 4-space indentation, using different styles for list items, or producing trailing whitespace that is invisible but breaks strict parsers. The YAML Formatter normalises all of this into a single consistent style in one step.
The formatter supports your choice of 2-space or 4-space indentation per level. Two spaces is the default for Kubernetes and GitHub Actions; four spaces suits teams that prefer more visual depth. All processing runs locally in your browser — the YAML you paste is never sent to a server. This is important when the YAML contains secrets, API keys, or deployment credentials, as is common in CI/CD and infrastructure configuration files.
For related structured data formats, use the JSON Formatter for JSON payloads or the XML Formatter for XML documents.
How to use this YAML calculator
- Paste your YAML into the Raw YAML input box — this can be a configuration snippet, a full manifest, or a YAML document of any length.
- Choose an Indent Size from the dropdown: 2 spaces (default, matches Kubernetes and GitHub Actions convention) or 4 spaces.
- The Formatted YAML output updates instantly. If the input is invalid YAML, the output shows the parse error message.
- Review the output to confirm the structure and values look correct.
- Click Copy to copy the formatted YAML to your clipboard.
Formula & Methodology
The YAML Formatter uses a two-phase approach built on theyamllibrary (YAML 1.2 compliant): Phase 1 — Parse:yaml.parse(input)converts the YAML string into a JavaScript value tree (nested objects, arrays, and primitives). If the input contains a syntax error,parsethrows an error with a message that includes the line and column of the problem. This error is caught and returned as the output string. Phase 2 — Stringify:yaml.stringify(parsed, { indent })serialises the JavaScript value tree back to a YAML string using the chosen indent size. The output is always canonical YAML 1.2: keys are not sorted but are preserved in the order they appeared in the input; strings that require quoting (empty strings, values that would be misread as booleans or nulls) are automatically quoted; trailing whitespace and blank lines at the end are trimmed. Before (inconsistent indentation):yaml server: host: localhost port: 8080 database: name: myapp user: adminAfter (2-space indent, normalised):yaml server: host: localhost port: 8080 database: name: myapp user: admin