YAML Formatter

Runs in browser Formatting

Parse YAML, report syntax errors with line numbers, and re-emit a clean document with chosen indentation, ideal for Kubernetes, Docker Compose, GitHub Actions and OpenAPI files.

Privacy: This tool runs entirely in your browser. Your input never leaves your device.
Loading tool…

What is YAML?

YAML is a human-friendly data format that uses indentation instead of braces, widely used for configuration (CI pipelines, Kubernetes, OpenAPI). YAML 1.2 is a superset of JSON: every JSON document is valid YAML, but YAML adds comments, anchors and implicit typing, which is where most surprises come from.

How to use YAML Formatter

  1. Paste the YAML.
  2. Choose indentation, collection style and quoting.
  3. Fix any reported error and copy the clean document.
The formatter parses YAML into data and prints that data again, so comments and anchors are lost and values may come back spelled differently.
  1. 1YAML textOne or more documents separated by ---
  2. 2ParseYAML 1.2 core schema, strict modeKeys must be unique; << merge keys are applied

    Branch: Syntax error, duplicate key or bad indentation (with line and column), or an alias bomb: an error, no outputFail

  3. 3Plain dataOptional: Sort keysComments are gone; anchors, aliases and merges become plain copies; explicit tags are dropped
  4. 4Re-emitChosen indentation, collection style and quoting; values keep their type but not always their spelling1.0 → 1, 0x1F → 31Formatted YAML

Then:Documents re-joined with ---

An unknown tag such as !Ref is dropped as well; the tool lists a warning for it.

YAML Formatter features

  • Parses YAML 1.2 and reports syntax errors with line, column and excerpt
  • Re-emits with 2 or 4-space indentation and consistent quoting
  • Block or flow style for collections, optional key sorting
  • Multi-document streams (---) are supported
  • Detects duplicate keys and alias bombs
  • Great for Kubernetes manifests, Docker Compose, GitHub Actions and OpenAPI files

YAML Formatter example

Normalise indentation

Input:

services:
    web:
        image: nginx
        ports: [ "80:80" ]

Output:

services:
  web:
    image: nginx
    ports:
      - 80:80

Frequently asked questions about YAML Formatter

Does it keep comments?

No. The document is parsed and re-emitted, so comments and anchors are resolved away. Use it for normalising indentation and quoting rather than for comment-heavy files.

What errors are reported?

Syntax errors with line and column, duplicate keys, bad indentation and unterminated quotes. The error excerpt shows the surrounding lines.

Can I format multi-document files?

Yes. Documents separated by --- are formatted individually and re-joined with --- separators.

Why did my "yes"/"no" or "1.0" values change?

The formatter parses the document into data and writes it back with the YAML 1.2 core schema, so values keep their type but not always their spelling. Numbers are rewritten in plain form (1.0 becomes 1, 0x1F becomes 31), and integers larger than 2^53 − 1 are rounded, which changes their value. Quotes YAML 1.2 does not need are dropped: "yes" and "on" are ordinary strings in YAML 1.2, so they come back unquoted. A string YAML 1.2 would read as a number, boolean or null, such as "1.0" or "true", stays quoted. YAML 1.1 parsers such as PyYAML read unquoted yes, no, on and off as booleans and 22:22 as a base-60 number, so tick "Quote all strings" when such a parser reads the file.

Technical notes

Formatting is parse-and-re-emit through the yaml package: parseAllDocuments runs in strict mode with uniqueKeys and merge enabled, then each document is normalised to JSON-safe values and printed again with lineWidth 0. Consequently anchors, aliases and << merge keys are expanded into plain copies, !!timestamp and !!binary become ISO 8601 and base64 strings, explicit tags are dropped, and integers above 2^53 − 1 are rounded. Under the 1.2 core schema, yes/no/on/off remain strings.

Because each document becomes a JavaScript object between parsing and printing, integer-like keys (0, 1, 42) are quoted and hoisted to the front in ascending order even with sorting off; 'Sort keys' then orders by UTF-16 code units, so uppercase precedes lowercase. Block sequences are indented under their parent key, multi-line strings become | literal blocks, 'Flow style' collapses a document onto one line, and streams are re-joined with --- (an empty document prints as null).

References