Skip to content
codevory

YAML Formatter & Validator

Validate and re-indent YAML while keeping comments, anchors and tags. Syntax errors point to the exact line and column.

YAML Formatter & Validator: the tool

Paste YAML to validate and re-indent it.

Input

Formatted YAML

The result appears here.

How to use YAML Formatter

  1. Paste YAML into the left panel, or press Example to load a configuration with uneven indentation.
  2. The formatted result appears on the right. Choose 2 or 4 spaces, and whether list items are indented under their key.
  3. Turn on Sort keys to order the keys of every mapping alphabetically. Comments move with their entries.
  4. If the YAML is invalid, the status bar gives the line and column. Press Go to error to jump to it.

Example

A configuration with irregular indentation and a flow mapping, formatted with 2 spaces. The comment is kept.

Input
# Service configuration
name:   codevory
server:
      host: localhost
      port: 8080
features:
        - json
        - yaml
limits: {maxMb: 10,   ratio: 0.5}
Output
# Service configuration
name: codevory
server:
  host: localhost
  port: 8080
features:
  - json
  - yaml
limits: { maxMb: 10, ratio: 0.5 }

About this tool

YAML uses indentation to express structure, so one misplaced space changes the meaning, and tabs are not allowed at all. The formatter parses the document with a YAML 1.2 parser, reports the first error, and prints the same data with consistent indentation. Comments, anchors (&name), aliases (*name), tags and block scalars are preserved.

Long text values are never rewrapped unless you turn on Wrap long lines, so a formatted file does not change line by line in a way that would clutter a diff. Documents separated by --- are formatted one by one. Duplicate keys in a mapping are treated as errors, as the YAML specification requires.

The data does not change when you format. A folded block (>) may be laid out on fewer lines, but its value is identical. Everything runs in your browser, so configuration files that contain internal names or secrets are not uploaded.

Common YAML mistakes

MistakeWhy it failsFix
Tab indentationTabs are not allowed to indentUse spaces
Mixed indentation levelsSiblings must start in the same columnAlign all keys of a mapping
Duplicate keyKeys in a mapping must be uniqueRename or remove one
Unquoted colon in text (a: b: c)A second colon starts a nested mappingQuote the text: a: "b: c"
Unclosed [ or {Flow collections must be closedAdd the closing bracket

Frequently asked questions

Are comments preserved when formatting YAML?

Yes. Comments are kept with the entries they belong to, including end-of-line comments, and they move along when you sort keys.

Why is yes or no not converted to true or false?

This tool follows YAML 1.2, where only true and false are booleans. In YAML 1.1, which older tools use, yes, no, on and off were booleans too, which famously turned the country code NO (Norway) into false. Quote the value if another tool needs a specific reading.

Does formatting change the data?

No. Mappings, lists and scalars keep their values. Only layout changes: indentation, spacing, and how some block scalars are laid out.

Does it support multiple documents in one file?

Yes. Documents separated by --- are all validated and formatted, and the separators are kept.

Can YAML use tabs?

Not for indentation. A tab can appear inside a value, but using one to indent a line is an error, and the message points at the line.