YAML Formatter

Pretty-print or compact YAML, with clear error messages when something doesn't parse. Comments aren't preserved — formatting re-serializes the parsed structure. Everything runs in your browser; nothing is uploaded.

0 chars0 lines0 bytes
0 chars0 lines0 bytes

What is YAML Formatter?

YAML Formatter is a browser-based tool that parses your YAML and re-serializes it with clean, consistent indentation — turning inconsistent spacing, mixed styles, and inline collections into readable block form. It also does the reverse: compact mode collapses your data into YAML flow style, the compact single-line representation that mirrors JSON.

YAML (YAML Ain't Markup Language) is the configuration language behind Kubernetes manifests, Docker Compose files, CI/CD pipelines (GitHub Actions, GitLab CI), Ansible playbooks, and countless application config files. Its human-friendly syntax is powerful but famously sensitive to indentation and whitespace, where a single misaligned space can change meaning or break parsing entirely. This tool catches those problems and normalizes the layout.

Because formatting works by fully parsing and re-emitting the document, comments are not preserved — the output reflects the parsed data structure, not the original text verbatim. Everything runs locally in your browser; your configuration, which may include hostnames, secrets, or infrastructure details, is never uploaded.

Why use YAML Formatter?

YAML's reliance on indentation makes it uniquely easy to break by hand. Tabs are forbidden, nesting depth is defined purely by spaces, and a value that looks fine can parse as the wrong type. YAML Formatter re-derives a correct, consistent layout from the parsed structure, so ambiguous or inconsistent indentation is replaced with a canonical form you can trust.

Switching between block style and flow style is genuinely useful. Block style is readable for humans editing config; flow style is compact for embedding a small structure inline or comparing it to JSON. Being able to flip between them instantly saves manual rewriting and reduces the chance of introducing a syntax error.

Validating locally protects sensitive infrastructure data. Config files routinely contain internal hostnames, environment names, credentials, and deployment details. This tool parses everything in your browser and sends nothing to a server — you can confirm zero network activity in your browser's Network tab while formatting.

Features

  • Pretty-print YAML into clean, consistently-indented block style
  • Compact YAML into single-line flow style (JSON-like) form
  • Validates as you type and reports parse errors clearly
  • Normalizes inconsistent indentation and mixed collection styles
  • One-click copy of the result to your clipboard
  • Download the formatted result as a .yaml file
  • Live character and line counts for input and output
  • Runs entirely in your browser — no uploads, works offline

How to use YAML Formatter

  1. Paste your YAML into the input panel on the left — a Kubernetes manifest, a docker-compose file, a CI config, or any YAML snippet.
  2. The formatted result appears in the right panel automatically as you type.
  3. Use the Format / Compact toggle to switch between readable block style and compact flow style.
  4. If the YAML has a syntax problem — such as a tab character or bad indentation — a clear error message appears below the tool.
  5. Copy the result to your clipboard or download it as a .yaml file once you are happy with it.

Example 1 — Normalize inline arrays to block style

Paste YAML that mixes inline flow collections with block mappings. Format mode re-emits everything as clean, consistent block style.

Input

name: my-app
ports: [80, 443]
env: {NODE_ENV: production}

Output

name: my-app
ports:
  - 80
  - 443
env:
  NODE_ENV: production

Example 2 — Compact to flow style

Switch to Compact mode to collapse a small structure into a single JSON-like line, handy for embedding inline.

Input

a: 1
b:
  - 1
  - 2

Output

{a: 1, b: [1, 2]}

Common Mistakes

  • Using tabs for indentation: YAML forbids tab characters for indentation — only spaces are allowed. A single tab causes an immediate parse error. If your editor inserted tabs, convert them to spaces first.
  • Inconsistent indentation depth: sibling keys must line up at exactly the same column. Mixing two and four spaces at the same level, or under-indenting a nested block, changes the structure or breaks parsing.
  • Unquoted special values: strings like yes, no, on, off, and null are interpreted as booleans or null unless quoted. A value like "no" for a country code becomes false unless you wrap it in quotes.
  • Expecting comments to survive: because formatting re-serializes the parsed data, comments are dropped. Do not run a heavily-commented config through the formatter if you need the comments preserved.
  • Colons inside unquoted values: a value containing a colon followed by a space (like a URL or time) can be misread as a nested mapping. Quote such values to keep them intact.
  • Trailing whitespace and hidden characters: invisible trailing spaces or non-breaking spaces pasted from a document can cause confusing parse failures that are hard to spot by eye.

Developer Tips

  • When a Kubernetes or CI pipeline rejects your YAML, paste it here first to confirm it is syntactically valid before assuming the problem is with the schema or the platform.
  • Use Compact (flow) style to quickly see how a YAML fragment maps onto its JSON equivalent — flow style and JSON are structurally very close.
  • Quote any value that could be mistaken for a boolean, number, or null (version numbers, country codes, port ranges) to avoid YAML's implicit type coercion surprising you at runtime.
  • Keep a commented copy of important config separately, since this formatter drops comments — format a copy, then reapply comments to your source file.
  • For multi-document YAML (files separated by ---), validate each document's structure individually if you hit an error, to isolate which document is malformed.

Frequently Asked Questions

Why does the formatter remove my comments?
Formatting works by parsing your YAML into a data structure and then re-serializing that structure with clean indentation. Comments are not part of the data — they live only in the original text — so they are lost during re-serialization. This is inherent to how a re-emitting formatter works. If you need comments preserved, keep your source file as the source of truth and only use the formatted output as a reference or for machine consumption.
What is the difference between block style and flow style?
Block style is the multi-line, indentation-based layout most people associate with YAML, where each key or list item sits on its own line. Flow style is a compact single-line form using braces and brackets that looks almost identical to JSON. Format mode produces readable block style; Compact mode produces flow style. Both represent the exact same data — they are just two ways of writing it.
Why does YAML forbid tabs?
YAML uses indentation to define structure, and tabs render at different widths in different editors, which would make indentation ambiguous. To guarantee that every parser interprets nesting identically, the YAML specification only permits spaces for indentation. A tab character where indentation is expected is always a syntax error. Configure your editor to insert spaces rather than tabs when working with YAML.
Is my YAML sent to a server?
No. All parsing and formatting happens locally in your browser using JavaScript. Your YAML — which often contains sensitive infrastructure details like hostnames, environment names, and occasionally secrets — is never uploaded, logged, or stored. You can verify this by opening your browser's Network tab while you format: there are zero outbound requests, and the tool keeps working even offline.
Why did my string value turn into true or a number?
YAML has implicit typing: unquoted values that look like booleans (yes, no, on, off, true, false), numbers, or null are automatically converted to those types. So an unquoted no becomes the boolean false, and 007 may become the number 7. To keep a value as a literal string, wrap it in single or double quotes. This is one of the most common sources of surprising YAML behavior.
Can I format Kubernetes or Docker Compose files here?
Yes. These are standard YAML, so the formatter will parse and re-indent them correctly and flag any syntax errors. Keep in mind that formatting validates syntax only, not schema — it confirms the YAML is well-formed, not that it is a valid manifest for a specific tool. Also remember comments will be stripped, which matters for heavily-annotated Compose or manifest files.
How does YAML formatting differ from JSON formatting?
JSON and YAML represent similar data, but YAML is far more whitespace-sensitive and supports comments, anchors, and multiple typing shortcuts that JSON does not. A JSON formatter mostly adjusts brackets and indentation, while a YAML formatter must handle indentation-defined structure, implicit typing, and block-versus-flow styles. YAML is also a superset of JSON, so valid JSON is valid YAML — but not the reverse.