YAML Formatter and Validator

Re-indent YAML, keep your comments, and find syntax errors with the exact line and column.

Paste your YAML

Loading the YAML parser...

How to format YAML with this tool

  1. Paste your YAML into YAML input. The page opens with an unevenly indented file so you can see the result at once.
  2. Choose Indent: 2 or 4 spaces.
  3. Keep Indent list items under their key ticked to indent list dashes under the key. Clear it to line them up with the key, as many Kubernetes files do.
  4. Keep Convert tab indentation to spaces ticked to repair tab-indented files, which YAML does not allow.
  5. Read the line under Formatted YAML. Green means valid. Red gives the line, column and reason for the first error, and Show error moves the cursor there.
  6. Click Copy result.

How the checking and formatting work

The page loads the open source yaml library (version 2.9.1, ISC licence) and parses your text as YAML 1.2. That gives exact positions for bad indentation, unclosed brackets, duplicate keys and aliases with no anchor. The parsed document is then written back with your indent. Comments, blank lines between sections, quote styles, block scalars, anchors, aliases and merge keys are kept. Plain values are copied as you typed them, so 1.0, 3.10, 0644 and yes are never rewritten as 1, 3.1, 644 or true.

Worked example

With the defaults (2 spaces, list items indented, tabs converted), this input from the page:

# Service settings
name: example
version: 1.0
services:
    - web
    - db
config:
   debug: true
   port: 3000

becomes:

# Service settings
name: example
version: 1.0
services:
  - web
  - db
config:
  debug: true
  port: 3000

The status line then reads: Valid YAML. 1 document. Formatted with a 2-space indent.

Limits and edge cases

Frequently asked questions

How do I find an indentation error in YAML?

Paste the file and read the red message under the result. It gives the line, column and reason for the first problem, such as mapping items that do not start at the same column. Click Show error to put the cursor there.

Why does YAML reject tabs?

The YAML specification allows only spaces for indentation, because tabs can display at different widths. With Convert tab indentation to spaces ticked, this tool replaces leading tabs when they cause the error and tells you which lines changed.

Does formatting keep my comments?

Yes. Comments, blank lines between sections, quote styles, anchors and aliases are kept. The tool changes the indentation and the spacing inside flow lists such as [1, 2, 3].

Why do yes and on turn into true in some tools?

YAML 1.1 parsers such as PyYAML read yes, no, on and off as booleans. This formatter checks YAML 1.2, where they are plain text, and leaves them as typed. Quote them if a 1.1 parser will read the file and you mean the words.

Can I format a Kubernetes or Docker Compose file?

Yes. Both are ordinary YAML. A file with several documents separated by three dashes is formatted one document at a time. Only YAML syntax is checked, not whether the keys are valid for Kubernetes or Compose.

Need another format? Try the YAML to JSON converter, the JSON formatter and validator, the XML formatter, or the diff checker to compare the file before and after.