YAML formatter

A YAML formatter takes a messy config file and prints it back with clean, consistent indentation. This page formats YAML, checks it against YAML 1.2, and converts it to JSON or back. It is free, there is no signup, and everything runs in your browser.

Last verified: November 15, 2026 · Primary source: YAML 1.2 specification · Independent tool, not affiliated with the YAML project

Format YAML

The status line checks the document as you type and never changes your input. Live formatting runs for inputs under 300,000 characters; longer inputs wait for the Format button. Formatting prints the file again from the parsed data, so comments are not kept. Numbers are printed exactly as written, including 1.30 and integers with more than 15 digits.

What the formatter changes

  • Indentation. Every mapping and sequence gets one level per nesting depth, with 2 spaces or 4 spaces. One key-value pair per line, so a diff shows exactly what changed.
  • Minify. The reverse: the whole document is printed in flow style, one line per document, for the smallest text to paste into a chat message or a ticket. It is still valid YAML.
  • Key order. Left alone by default. Tick Sort keys A to Z when you need two documents to line up for a diff.
  • Numbers. Printed exactly as written. 1.30 stays 1.30 and 12345678901234567890 stays whole, where most browser formatters would print 1.3 and round the integer.
  • Strings. Plain where it is safe, quoted where it is not. A value that looks like a boolean or a number, such as true or 123, comes back in double quotes so the next parser reads it as a string.
  • Comments. Not kept. Formatting re-prints the file from the parsed data, and comments are not data. If the file is full of comments you want to keep, use Validate only instead: it checks the file and never changes your input.

What validation catches

Formatting doubles as validation: if the text does not parse, the page tells you exactly where it broke instead of failing quietly. The parser on this page is written for YAML 1.2, the current specification, and it checks five things most formatters skip.

Exact error position

Every error names a line and a column, and the message says what was expected. A tab used for indentation, an unclosed quote, a mapping value that contains a colon and a space, a flow collection that never closes: each gets its own plain sentence. The first error is shown; fix it and check again, because one mistake early on can hide the next one.

Duplicate keys

Two keys with the same name in one mapping are the quietest config bug. Most parsers keep only the last value and stay silent, so a file with two port entries runs on the second one and nobody notices. You get an error with the line and column of the second key, and the line of the first one.

The YAML 1.1 boolean trap

YAML 1.2 counts only true and false as booleans. YAML 1.1 also counted yes, no, on, off, y and n, and some parsers still do. A value of yes is a string on this page, but a 1.1 parser reads it as true. The page warns you whenever one of those words appears as a key or a value, so you can quote it before it reaches a parser that disagrees.

Anchors, aliases and merge keys

Anchors (&base), aliases (*base) and merge keys (<<: *base) are resolved, and the formatted output shows the merged result. An alias that points at an anchor that was never defined stops the parse with an error.

Document statistics

A valid document reports its shape: how many documents, mappings, sequences and keys it holds, and how deep the nesting goes. That is the fastest way to tell whether a 2 MB Kubernetes manifest is one flat list or a tree six levels deep before you start editing it.

The on: trap in GitHub Actions

A GitHub Actions workflow starts with a trigger key called on:

name: CI
on:
  push:
    branches: [main]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - run: npm test

Under YAML 1.1, on is the boolean true, so the key becomes true: and the workflow never triggers. GitHub reads workflows with a 1.2 parser, so on stays a string there, but the same file breaks the moment a 1.1 tool touches it: an editor plugin, a linter, a script that rewrites the file. The fix is one pair of quotes, "on":, or a formatter that warns you first. Load the GitHub Actions sample above the page to see the warning on a real workflow.

The same trap hides in values. enabled: yes is the string "yes" in YAML 1.2 and the boolean true in YAML 1.1. If a deploy depends on that value being a string, quote it: enabled: "yes". The warning on this page lists every spot where the two versions disagree, so you can decide case by case instead of finding out in production.

Common YAML errors

ErrorWhat it usually means
Tabs for indentationYAML forbids tab characters for indentation. A tab looks like 2, 4 or 8 spaces depending on the editor, so the structure is ambiguous. Replace tabs with spaces.
Unclosed quoteA quote opened but never closed on the same line. Quoted strings cannot span lines; use a block scalar (| or >) for multi-line text.
Colon and space in a plain valueA plain scalar cannot contain : . url: http://example.com:8080 is fine, but note: see: below is not. Quote the value.
Duplicate keyThe same key twice in one mapping, usually from a bad merge. Most parsers keep only the last value and stay quiet. Delete one of them.
Undefined aliasAn alias such as *base with no &base anchor above it. Check the spelling, or define the anchor first.
Inconsistent indentationA line indented one level too far, or a sibling key at a different depth from its neighbours. Count the spaces: 2 per level is the usual choice.
Flow collection never closesA { or [ with no matching closer on the same line. Flow collections on this page must fit on one line; use block style for long ones.
Tag not supportedA tag such as !!str in the input. Tags are not supported on this page; remove the tag or use a plain value.

Five of these have no one-click fix, because guessing would change what the file means. The page shows the first error with its line and column; fix it and check again.

Worked example

A short Docker Compose file, as it usually arrives: mixed indentation, a list written three ways.

services:
 db:
  image: postgres:16
  environment:
   POSTGRES_PASSWORD: secret
  volumes:
   - db-data:/var/lib/postgresql/data
volumes:
 db-data:

After formatting with 2 spaces:

services:
  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: secret
    volumes:
      - db-data:/var/lib/postgresql/data
volumes:
  db-data:

The same document answers three questions without scrolling. The status line reports 2 mappings, 1 sequence, 6 keys and a max depth of 4. Switch the output to YAML to JSON to see the same file as JSON. Load the Kubernetes sample above the page to try a larger file.

Format YAML in code

Use a maintained tool in production. The three below are the usual choices: a linter, a code formatter, and a Python one-liner.

yamllint, from the command line

yamllint docker-compose.yml

Checks indentation, key order and duplicate keys against a config file. It reports problems; it does not rewrite the file.

Prettier, from the command line

npx prettier --write docker-compose.yml

Rewrites the file with consistent indentation. It uses a YAML parser of its own, so a file it rejects will usually fail here too, with the same first error.

Python, standard library only

python3 -c "import sys, yaml; print(yaml.safe_dump(yaml.safe_load(sys.stdin), sort_keys=False))" < docker-compose.yml

Reads YAML and prints it formatted. Note the trade-off: PyYAML follows YAML 1.1, so it reads on as true and yes as true. That is exactly what the warnings on this page exist to catch.

Frequently asked questions

Is my YAML uploaded anywhere?

No. The parser runs in your browser. Nothing is uploaded, nothing is logged, and the page works offline once loaded. Even so, remove API keys and personal data before pasting into any online tool.

Does formatting keep my comments?

No. The formatter prints the file again from the parsed data, and comments are not data. If the file is full of comments you want to keep, use Validate only: it checks the file as you type and never changes your input.

Which YAML version does it check?

YAML 1.2, the current specification. That means only true and false count as booleans. Words such as yes, no, on and off are plain strings here, and the page warns you when one appears, because some older parsers still read them as booleans.

Does it catch duplicate keys?

Yes, with the line and column of the second one. Duplicate keys are the quietest config bug: most parsers keep only the last value and stay silent, so a file with two port entries runs on the second one and nobody notices.

What is the on: trap in GitHub Actions?

A workflow that starts with on: push uses on as the trigger key. Some YAML 1.1 parsers read on as the boolean true, so the key becomes true: and the workflow never triggers. This page follows YAML 1.2, where on is a string, and warns you whenever on, off, yes or no appears as a key or a value.

Can I convert JSON to YAML?

Yes. Switch the output to JSON to YAML and paste JSON. The converter checks the JSON first, reports duplicate keys, and prints the result with the indentation you chose. Switch the other way to turn YAML into JSON, with large integers kept whole.

Sources

YAML.org, YAML 1.2 Specification: the standard this page checks against, including the core schema, the block scalar rules, and the anchor and merge key rules.

GitHub Docs, Workflow syntax for GitHub Actions: the on: trigger key and the workflow structure behind the on: trap section above.

Kubernetes Documentation, Understanding Kubernetes Objects: the manifest structure used in the Kubernetes sample, including apiVersion, kind, metadata and spec.

Docker Documentation, Compose file reference: the services, volumes and environment structure used in the worked example.

Agents

Machine readable summary for AI assistants: