Skip to content
Case Converter Online
en

YAML Formatter and Validator

Paste YAML to fix its indentation and spacing, or check it for errors before you deploy. Comments are kept, and problems are reported with the line and column.

Paste YAML or press Sample. Press Ctrl and Enter to format. Everything runs in your browser.

What the YAML formatter does

YAML is the format behind Docker Compose files, Kubernetes manifests, GitHub Actions workflows, Ansible playbooks and many app configs. Its structure comes from indentation, so a single misplaced space can change what a file means or stop a deploy. This tool rewrites your YAML with consistent indentation and spacing, and checks it with a strict parser so problems show up here instead of in your pipeline.

It has two actions:

  • Format normalises indentation, the spaces after colons and dashes, and the spacing inside [ ] and { }.
  • Validate parses the file and reports the first error, or a short summary when it is valid.

How to use it

  1. Paste YAML into the left box. It is formatted as soon as you paste. You can also use Open file for .yaml and .yml files, or Sample for an example.
  2. Choose an Indent of 2 or 4 spaces and a Line width.
  3. Turn on Single quotes if your project prefers 'text' over "text".
  4. Press Format or Validate. Ctrl+Enter runs the last action again.
  5. Press Copy, or Download to save a .yaml file.

Before and after

A Docker Compose file with uneven spacing and 4-space indents:

version:   "3.8"
services:
    web:
        image:   "nginx:latest"
        ports:
            - "80:80"
        environment:
            - DEBUG=false
    db:
        image: postgres:16

After Format with 2 spaces:

version: "3.8"
services:
  web:
    image: "nginx:latest"
    ports:
      - "80:80"
    environment:
      - DEBUG=false
  db:
    image: postgres:16

Flow collections get even spacing. tags: [ api, v2 ] and limits: {cpu: 1, memory: 512} become:

tags: [api, v2]
limits: { cpu: 1, memory: 512 }

Comments survive. The extra spaces before an end-of-line comment are tidied, but the comment stays on its line:

# Database settings
db:
  host: localhost # local only
  port: 5432

With Single quotes on, name: "web" becomes name: 'web'. A string that contains an apostrophe, such as "it's here", keeps its double quotes so no escaping is needed.

Errors the validator catches

YAML parsers in different tools are not equally strict. This one flags problems that some tools let through. Real messages from the tool:

Problem Message
The same key twice Line 3, column 1: Map keys must be unique
A tab used for indentation Line 2, column 1: Tabs are not allowed as indentation
A line indented one space too far Line 2, column 9: Nested mappings are not allowed in compact mappings

The duplicate key check matters most. In a file such as name: web, port: 80, name: api, many loaders keep only the last name without a warning. Press Show in input to jump to the line.

For a valid file with two documents separated by ---, Validate reports: Valid YAML. 2 documents.

Tips and limits

  • The formatter does not reorder keys or change values. yes, on and 010 are left as you wrote them.
  • Long strings are not rewrapped. Folded (>) and literal (|) blocks keep their content.
  • Anchors and aliases (&name, *name) are kept as written.
  • YAML has no minified form in common use, so there is no Minify button. If you need compact data, convert it with the JSON to YAML Converter in the YAML to JSON direction.

Other ways to format YAML

VS Code. The Red Hat YAML extension adds formatting and schema checks for files such as Kubernetes manifests. Run Format Document after installing it.

yq. The Go version of yq (by Mike Farah) reads and rewrites YAML. yq '.' file.yaml prints the file back in its own consistent style, and the same tool can query and edit values.

Prettier. If your project already uses Prettier, it formats .yaml and .yml files with the same rules as this page.

yamllint. A Python tool that checks style and syntax without rewriting the file, useful in CI.

To turn JSON into YAML or back, use the JSON to YAML Converter. For JSON files, use the JSON Formatter. For XML configs such as Maven or Android files, use the XML Formatter.

YAML Formatter: questions and answers

Why can I not indent YAML with tabs?

The YAML specification does not allow tab characters for indentation, only spaces. That is why the Indent menu offers 2 or 4 spaces and no Tabs option, and why the validator reports tabs as an error.

Are my comments kept?

Yes. Comments stay where they are. The formatter only changes spacing, indentation and line layout. Keys and values keep their order.

Does the formatter catch duplicate keys?

Yes. If the same key appears twice in one mapping, you get an error such as Map keys must be unique, with the line of the second key. Many YAML tools silently keep only the last value, which can hide a mistake.

Can it handle files with several documents?

Yes. Documents separated by --- are formatted together, and Validate tells you how many documents it found.

Is it safe for Kubernetes secrets or CI files?

The YAML is processed in your browser and is not uploaded. Still, avoid pasting live secrets into any web page if your company policy forbids it.

More code and data tools

See all tools