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 is powered by a lightweight, custom-built parser that targets the "common subset" widely used in Docker Compose, GitHub Actions, and Kubernetes manifests — mappings, lists, inline flow collections, and basic scalar types. It doesn't support advanced features such as anchors (&), aliases (*), multiple documents, or block scalars (|/>), so if you're working with YAML that relies on those features, you'll want to pair this tool with a full-spec parser.

How to Use the YAML Formatter

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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 uses a lightweight custom-built parser, supporting key: value pairs, nesting, lists, and inline [a, b, c] / {a: 1} syntax.
  • 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 where content defined with &name can be reused elsewhere with *name, avoiding repeated values. This tool does not support them.
Block scalar
A way of writing multi-line strings using | (which preserves line breaks) or > (which folds them into spaces). This tool does not support it.
Norway Problem
A well-known YAML gotcha where unquoted values like no or yes get interpreted as booleans rather than plain strings.

Frequently Asked Questions

YAML is a good fit for config files that humans edit and review by hand (CI configs, Kubernetes manifests, etc.) since it supports comments and reads more naturally. JSON is better suited to program-to-program communication, like API responses, since it's less ambiguous and parses faster.

The YAML spec forbids using tab characters for indentation. Most parsers will treat it as a syntax error and stop processing. It's safest to configure your editor to automatically convert tabs to spaces.

No. This tool targets the "common subset" typically used in Docker Compose, GitHub Actions, and similar files (mappings, lists, inline flow collections, and basic scalar types), and doesn't support advanced features like anchors, aliases, multiple documents, or block scalars (|/>).

It's a famous gotcha where writing 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".
Tool-kun

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.

That said, YAML's design of "structure through indentation" is easy for humans to read, but also fragile: indentation breaks easily when copy-pasting. In particular, mixing tabs and spaces can cause many parsers to silently produce the wrong structure without raising an error, which makes it a common source of unintended 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.