Skip to content

YAML Formatter & Validator

Paste YAML to fix its indentation and check it for errors. Comments, anchors and multiple documents are kept.

Input
Formatted YAML

    
Ready

Last reviewed:

What is YAML?

YAML is a data serialisation format designed for humans to read and edit. It is the configuration language of Kubernetes, Docker Compose, GitHub Actions, GitLab CI, Ansible, OpenAPI and many application frameworks. Instead of brackets, YAML uses indentation to show structure: a key followed by a colon starts a mapping, a line starting with - is a list item, and anything indented further belongs to the line above. It also has comments (#), multi-line strings (| keeps line breaks, > folds them), anchors and aliases for reuse (&name and *name), and several documents in one file separated by ---.

The price of that readability is fragility. Indentation must use spaces, never tabs, and a single space too many or too few changes which parent a key belongs to, or makes the file invalid. Because the same data can be written in several styles (block or flow lists, single or double quotes, two or four-space indents), files edited by many people drift into a mix that is hard to review.

A YAML formatter parses the file and prints it back in one consistent style, without changing the data. This tool uses Prettier's YAML printer, the same formatter many teams run in their editors and pre-commit hooks. Unlike a convert-and-dump approach, it keeps comments, anchors, aliases, merge keys, block scalars and document separators.

How to use this tool

  1. Paste YAML into Input or click Paste. Sample loads a deliberately messy service config with inconsistent indentation, a flow list, a comment, an anchor and two documents.
  2. Choose an indent of 2 spaces or 4 spaces.
  3. Choose a quote style. "Double" quotes and 'Single' quotes set which quote character is preferred for strings that are already quoted. Unquoted values stay unquoted.
  4. Choose how long text is handled: Keep line breaks leaves line breaks in long strings as they are, Wrap long text reflows long plain strings onto several lines at 80 columns, and Unwrap long text joins wrapped plain text back onto one line.
  5. With Format as I type on, the output updates as you edit; otherwise click Format. If the YAML is invalid, the status line shows the problem with its line and column.
  6. Click Copy, or Download to save formatted.yaml.

Examples

Normalising a hand-edited config

Input:

name:   api
replicas:    3
env:
- name: NODE_ENV
  value: 'production'
-   name: LOG_LEVEL
    value: info
ports: [ 80,443 ]
healthcheck:
    path: /health   # checked by the load balancer
    interval: 30

Output with 2 spaces and double quotes:

name: api
replicas: 3
env:
  - name: NODE_ENV
    value: "production"
  - name: LOG_LEVEL
    value: info
ports: [80, 443]
healthcheck:
  path: /health # checked by the load balancer
  interval: 30

Extra spaces after colons are removed, list items are indented under their key, the flow list is tidied but kept as a flow list, and the comment survives. The quoted 'production' switches to double quotes; with 'Single' quotes chosen it would stay single. A string that contains an apostrophe, like "it's", keeps double quotes either way, so no escaping is needed.

Anchors, merge keys and multiple documents

With 4 spaces:

defaults: &defaults
    timeout: 5
worker:
    <<: *defaults
    queue: emails
enabled: yes
version: 1.10
---
kind: second-document

The anchor, alias and merge key are preserved, and both documents are kept. Values are not reinterpreted: yes and 1.10 are printed exactly as written. A converter that loads and re-dumps the data could turn 1.10 into 1.1.

Wrapping long text

With Wrap long text, a long plain value is reflowed:

description:
  This service handles outgoing email for the platform, including retries,
  bounces and the daily digest that is sent to every active user.

It still parses to the same single-line string, because line breaks in plain scalars fold into spaces.

Common errors and how to fix them

  • "Tabs are not allowed as indentation". YAML forbids tab characters for indentation. Replace them with spaces; most editors can convert them for you.
  • "Nested mappings are not allowed in compact mappings". Usually a value containing : , such as command: echo a: b, or a key indented under a scalar value like a: 1 followed by b: 2. Quote the value ("echo a: b"), or fix the indentation so the nested key belongs to a key without a value.
  • "Flow sequence in block collection must be sufficiently indented and end with a ]". A [ list is not closed. Add the ], or rewrite the list as - items.
  • "Unexpected scalar at node end". A list and a mapping are mixed at the same level, for example - a followed by b: 1. Decide whether that level is a list or a mapping and indent accordingly.
  • Duplicate keys. The formatter keeps both copies of a key such as a: 1 and a: 2. Most parsers then use the last value silently, and some reject the file. Search for the key and remove the duplicate.
  • A value changes type when loaded. Formatting will not change on, no, 0755 or 1.10, but a YAML 1.1 parser may read them as booleans or octal numbers. Quote values that must stay strings.

When developers use this

  • Cleaning up a Kubernetes manifest or Helm values file before a pull request so reviewers see consistent indentation.
  • Finding the exact line of a syntax error when kubectl apply, Docker Compose or a CI pipeline rejects a file with a vague message.
  • Normalising GitHub Actions or GitLab CI workflows copied from documentation and forum answers in different styles.
  • Converting a file to the team's chosen indent width without disturbing comments.
  • Preparing two versions of a config so a diff shows real changes rather than whitespace noise.

Privacy and how it works

Prettier and its YAML plugin run in your browser tab. Your YAML is not uploaded or stored, and nothing runs on a server. That matters because configuration files often hold database URLs, internal hostnames, API keys and secrets, or base64 values in Kubernetes Secret manifests. Even so, rotate any secret that has been pasted anywhere you do not control.

Limitations

  • The tool checks syntax, not meaning. It will not tell you that a Kubernetes field is misspelt or that a required key is missing; use a schema-aware validator for that.
  • Duplicate keys are not reported.
  • The quote option only changes the preferred quote character. It does not add quotes to unquoted values or remove quotes that are needed.

FAQ

Will formatting change my data?

No. The formatter changes indentation, spacing and quote characters, but the parsed values stay the same. It does not convert yes to true or reorder keys.

Are comments kept?

Yes. Comments stay attached to the line or block they were written next to, including trailing comments after a value, which are separated from it by a single space.

Should I use 2 or 4 spaces?

Two spaces is the most common convention for Kubernetes, Compose and CI files and is what Prettier uses by default. Use four if your project's existing files do; consistency matters more than the number.

Why are my list items indented under the key?

Prettier indents block sequences inside a mapping (env: then - name: …). YAML also allows the dash at the same column as the key, and both forms parse identically. The indented style makes nesting easier to see.

Does it support multiple documents?

Yes. Documents separated by --- are formatted individually and kept in order, as in a multi-resource Kubernetes file.

Why does single quote mode leave some strings in double quotes?

Prettier chooses whichever quote needs fewer escapes. A string containing an apostrophe keeps double quotes, so the content does not need to be escaped.

Can it fix invalid YAML automatically?

No. Any automatic guess could change the structure of your data. The tool reports where parsing failed so you can make the fix yourself.

Guides