YAML Formatter

Format and validate YAML with consistent indentation and optional key sorting.

Input data is processed in your browser
Data is never sent to a server

Tool

0 chars

or drag & drop a file

What is YAML Formatter?

YAML Formatter reformats YAML into a clean, consistently indented structure. It can also sort keys alphabetically and validates syntax at the same time. Useful for tidying up Docker Compose, GitHub Actions, Kubernetes, and other configuration files.

When this comes in handy

  • Indentation is inconsistent across a file and you want to standardize it: even YAML that mixes 2-space and 4-space indentation gets re-output with your chosen indent width.
  • You want the keys organized for easier scanning: turn on “Sort keys” to alphabetically reorder the keys at every level.
  • You want to confirm a docker-compose.yml or GitHub Actions workflow file is syntactically valid: just run it through the formatter and any parse error will be surfaced immediately.
  • You want to see YAML that uses anchors (&) and aliases (*) with the references already resolved: useful when you want to see the actual values in YAML that reuses shared config, without manually tracing the references.

Usage examples

Example 1: Formatting with 2-space indentation

Input:

name: Torinoa Tools
version: "1.0.0"
features:
  - free
  - no-login
  - browser-only

Formatted (2-space indent, no sorting):

name: Torinoa Tools
version: 1.0.0
features:
  - free
  - no-login
  - browser-only

Example 2: Formatting with 4-space indentation and sorted keys

With the same input, switching the indent width to 4 spaces and turning on “Sort keys” produces:

features:
    - free
    - no-login
    - browser-only
name: Torinoa Tools
version: 1.0.0

The keys are reordered alphabetically (featuresnameversion), and the array elements are indented with 4 spaces.

Example 3: Expanding anchors and aliases

Input:

defaults: &defaults
  adapter: postgres
  timeout: 30
production:
  <<: *defaults
  database: prod_db

Formatted:

defaults:
  adapter: postgres
  timeout: 30
production:
  adapter: postgres
  timeout: 30
  database: prod_db

The <<: *defaults reference is resolved, and the contents of defaults are inlined directly into production.

Example 4: Entering YAML with a syntax error

Input:

name: Torinoa Tools
  version: 1.0.0

The indentation of version is invalid, so formatting produces this error:

YAML parse error: bad indentation of a mapping entry (2:10)

Check that the indentation depth is consistent throughout the file.

How to Use

  1. Paste YAML text into the input field.
  2. Click "Format" to pretty-print with consistent indentation.
  3. Set the indent width (2 or 4 spaces) and optionally sort keys alphabetically.
  4. Click "Copy Result" to copy to clipboard.

FAQ

Can it detect YAML syntax errors?

Yes. If you enter invalid YAML, a parse error message is displayed.

Are comments preserved?

No. Comments are removed during the parse and re-dump process.

How are anchors and aliases handled?

Anchors and aliases are expanded and inlined in the output.

Is my data sent to a server?

No. All processing happens in your browser.

Are long arrays or strings automatically wrapped?

No. Line wrapping is disabled, so even long values are output on a single line. You don't need to worry about unexpected line breaks being inserted.

How does key sorting work?

Turning on "Sort keys" alphabetically reorders the keys within each mapping (object), applied recursively to nested mappings as well. Leave it off to preserve the original key order.