YAML Formatter
Format YAML with a consistent indent width, or convert it to JSON. Detects tab characters and inconsistent indentation.
What Is a YAML Formatter?
A YAML formatter takes YAML with inconsistent indentation and rewrites it with a uniform 2- or 4-space indent, while validating the syntax along the way. Configuration files tend to accumulate indentation drift after repeated copy-pasting and manual edits, and often the first sign of trouble is a cryptic error from your CI/CD pipeline or config-management tool long after the damage was done. Because this tool runs entirely in your browser, you can check sensitive configuration files without sending their contents to an external server.
This tool runs on an open-source parser (yaml) that follows the YAML 1.2 specification, and supports anchors (&) and aliases (*), block scalars (| and >), and multiple documents separated by ---. Booleans and nulls are resolved with the YAML 1.2 core schema, so unquoted no or on stay strings. Duplicate keys at the same level are reported as errors with a line number, and when converting to JSON, a multi-document stream becomes an array with one value per document.
How to Use the YAML Formatter
- Paste your YAML Paste the YAML you want to format into the input box on the left. If you don't have a sample handy, click the "Sample" button to insert some YAML you can experiment with.
- Choose a mode Pick "Format & Validate" to check the syntax and normalize the indentation, or "Convert to JSON" to render the YAML content as JSON.
- Choose the indent width In "Format & Validate" mode only, choose 2 or 4 spaces for the output indent, matching whatever convention your project already follows.
- Review the output If the YAML is valid, the formatted result (or the JSON conversion) appears on the right. If it isn't, an error message and line number appear so you can jump straight to the problem line.
- Copy the result Click "Copy" to copy the output to your clipboard so you can paste it straight back into your configuration file.
Tips for getting more out of it
- This tool parses input with an open-source parser (yaml) that follows the YAML 1.2 specification, so anchors, aliases, block scalars and multiple documents separated by
---all work. Formatting keeps your comments and quotes as written. - Even if you paste YAML with inconsistent indentation (3 or 5 spaces, for example), it will be re-output with a uniform 2- or 4-space indent as long as it parses successfully.
- In "Convert to JSON" mode, you can preview your YAML converted straight to JSON — handy for comparing against CI configs or API responses.
- If you get an error, the line number is shown, so check that line for indentation problems or a missing space after the colon.
- YAML forbids tab-based indentation. Enabling "convert tabs to spaces" in your editor settings can help you avoid this pitfall entirely.
When to Use This Tool
Pre-commit checks for CI configs
Run your GitHub Actions or GitLab CI .yml files through this tool before committing, to catch broken indentation or stray tabs before the pipeline fails on a syntax error.
Cleaning up Kubernetes manifests
Deployment and Service manifests edited by several people tend to end up with inconsistent indentation. Normalize them to your team's convention (2 spaces, for example) before sending them for review.
Validating Docker Compose files
Indentation mistakes in docker-compose.yml are often invisible until the container fails to start. Checking the syntax and indentation here first gives you peace of mind.
Comparing YAML and JSON side by side
When you need to work with the same configuration or API data in both YAML and JSON, "Convert to JSON" mode lets you check the conversion result, which you can then feed into JSON-based tools or schema validators.
Glossary
- YAML
- A recursive acronym for "YAML Ain't Markup Language," a data serialization format that expresses hierarchical structure through indentation. It's widely used for configuration files.
- Indentation
- The leading whitespace on a line, which YAML uses to express parent-child relationships. Per the spec, tab characters can never be used for indentation.
- Mapping
- A structure that represents data as "key: value" pairs, equivalent to an associative array or object in other languages.
- List (sequence)
- A structure that lists values in order, with each item introduced by a hyphen and a space ("- ").
- Flow style
- A way of writing mappings and lists inline on a single line, such as
{a: 1}or[a, b, c], without relying on indentation. - Anchors and aliases
- A mechanism that defines content with
&nameand reuses it with*name, avoiding duplication of the same value. This tool keeps them as written when formatting and expands them to the referenced value when converting to JSON. - Block scalar
- A way to write multi-line strings using
|(preserves line breaks) or>(folds line breaks into spaces). This tool supports them both when formatting and when converting to JSON. - Norway Problem
- A well-known YAML gotcha where unquoted values like
nooryesget interpreted as booleans rather than plain strings.
Frequently Asked Questions
<<: *name) used in files such as Docker Compose are expanded as well. Multiple documents and block scalars (|, >) are also supported.no, yes, on, or off without quotes gets interpreted as a boolean by many YAML implementations instead of a plain string (such as Norway's country code). If you want it treated as a string, wrap it in quotes, e.g. "no".
Side Note — Why YAML Became the Go-To Config Format
YAML (YAML Ain't Markup Language) is a data serialization format that appeared in 2001. Since it requires no closing tags and looks much simpler than XML, it has become the standard choice for infrastructure config files since the 2010s — Docker Compose, GitHub Actions, and Kubernetes manifests all use it.
On the other hand, YAML's design of expressing structure through indentation, while easy for humans to read, makes it fragile when copying and pasting. Using tabs for indentation is forbidden by the specification, and the major parsers reject it as a syntax error. The trickier case is spaces that are off by a few: the file may still parse without any error but put an item at a different level than you intended, which easily leads to subtle configuration mistakes.
There's also a well-known pitfall called the "Norway Problem." Writing the country code no without quotes gets interpreted as the boolean false by many YAML implementations. Differences in which strings count as booleans between YAML 1.1 and 1.2 are also a frequent source of cross-implementation compatibility issues.