YAML prettify and format

Format and validate YAML.

loading YAML prettify and format
About this tool

What is a YAML formatter?

YAML is the configuration format behind Docker Compose files, Kubernetes manifests, GitHub Actions workflows, OpenAPI specs, Ansible playbooks and many .yml settings files. It relies on indentation instead of braces, which makes it pleasant to read and easy to break: one misaligned line, one tab, or one repeated key and the file means something else or does not load at all. A YAML formatter (or prettifier, validator, viewer) reads the text, tells you whether it is valid and writes it back with consistent indentation and a clean layout.

This tool parses your YAML with a YAML 1.2 parser and prints it again in block style. Short inline forms such as {x: 1, y: [1, 2]} become regular indented lines, list items get the same indentation, and long text is wrapped. You choose the indent size and can sort the keys alphabetically, which is useful before you compare two files or commit a config that several people edit.

Be aware of what "formatting" means here, because it is more than whitespace. The tool reads the data and writes it out again, so comments are not kept, anchors and aliases (&base, *base, <<: *base) are expanded into plain copies, and a document with several parts separated by --- is formatted part by part. If you need to keep comments, edit the file by hand and use this page only to find the error. Everything runs in your browser and your YAML is not uploaded or stored; only your options (indent and sort) are remembered.

How to format and validate YAML online

  1. Paste your YAML in the input box. The page starts with a small example so the output is never empty; use the example button to bring it back and the clear button to start from nothing.
  2. Read the Formatted YAML below. It updates a moment after you stop typing.
  3. Set the Indent size (1 to 10 spaces, 2 by default). Two spaces is the usual choice for Kubernetes, Compose and GitHub Actions.
  4. Turn on Sort keys to order the keys of every mapping alphabetically. Leave it off to keep the order you wrote, which matters when the order carries meaning to you.
  5. If the text is not valid YAML, the output stays empty and a message gives the line, the column and the reason, for example Invalid YAML at line 2, column 1: this key appears twice in the same block; keys must be unique. Fix that line and the result returns on its own.
  6. Press the copy button to take the formatted result.

Examples

Expand the compact form

Input:

name: toolbox
items:
  - a
  - b
nested: {x: 1, y: [1, 2]}

Output with indent 2:

name: toolbox
items:
  - a
  - b
nested:
  x: 1
  y:
    - 1
    - 2

Anchors and merge keys become plain values

Input:

base: &base
  image: node:22
  restart: always
web:
  <<: *base
  ports: ["80:80"]

Output:

base:
  image: node:22
  restart: always
web:
  image: node:22
  restart: always
  ports:
    - 80:80

The merge is resolved, so each service shows every value it really gets. This is handy to debug a Compose or CI file that reuses blocks.

Sort the keys

Input zeta: 1, alpha: 2 and mid: {b: 1, a: 2} with Sort keys on:

alpha: 2
mid:
  a: 2
  b: 1
zeta: 1

Numbers and quotes can change

Input:

version: 1.10
port: 08080
msg: "yes"

Output:

version: 1.1
port: 8080
msg: yes

The parser follows YAML 1.2: 1.10 is the number 1.1 and 08080 is the integer 8080. If a value must stay text, write it as a quoted string, such as version: "1.10", which is kept. Note that the quotes around "yes" are dropped because YAML 1.2 reads yes as text; older YAML 1.1 parsers would read it as a boolean, so check the parser that will consume your file.

Common errors and how to fix them

  • This key appears twice in the same block; keys must be unique: name: a followed by name: b in the same mapping. Delete or rename one of them.
  • A tab was used to indent; use spaces: YAML forbids tabs as indentation. Replace them with spaces; most editors can convert them.
  • Wrong indentation; align it with the lines above: a child is indented less or differently than its siblings. Line up the items of the same level.
  • Unexpected indentation: a line is indented under a value that cannot have children, as in a: 1 followed by b: 2. Remove the extra spaces or turn the value into a mapping.
  • A closing character is missing (quote, bracket or brace): an opening ", [ or { was never closed. The line and column point to where it started.
  • Several documents: if your file has --- separators, each part is formatted and joined back with ---; an error in any part blocks the whole output.

Frequently asked questions

How do I validate YAML online?

Paste it above. If it is valid you see the formatted version; if not, you get the line, the column and the reason. It checks the YAML syntax, not the schema of Kubernetes, Compose or any other tool.

Does the formatter keep my comments?

No. It reads the data and writes it back, so lines starting with # and comments at the end of a line are removed. Copy them back by hand, or use the tool only to locate the error in the original file.

How do I convert YAML to JSON?

Use YAML to JSON. To go from JSON to YAML use JSON to YAML, and to read the result comfortably use the JSON formatter.

How do I fix the "mapping values are not allowed here" error?

That wording comes from other parsers. It usually means a : appears where the parser expected plain text, or a line has the wrong indentation. Here the same cases show up as an indentation message with its line and column.

Can I use it for a docker-compose file?

Yes, to check the syntax and tidy the indentation. To turn a docker run command into a Compose file use the docker run to compose converter.

Report a problem