Skip to content
gohacks.dev
DevOps

YAML Formatter and Validator

Validate YAML and reformat it with consistent 2 or 4 space indentation, optional key sorting and every document in a multi-document file.

Free · No sign-up · Your inputs stay in your browser

Input

Format and validate YAML

Output

Formatted YAML

1 document, contains yes/no/on/off: YAML 1.1 parsers read those as booleans

Parsed with js-yaml as YAML 1.2, then written back in block style. Comments are not part of the data model, so they are dropped: format a copy, not the only one. Anchors and aliases are expanded.

Runs in this browser. Nothing you paste is sent to a server.

The errors YAML is known for

Tabs are not allowed for indentation, a colon followed by a space inside an unquoted value starts a new mapping, and in YAML 1.1 parsers the words yes, no, on and off are booleans (the Norway problem: the country code NO becomes false). Kubernetes and Docker Compose use YAML 1.1 style parsers in places, so quote those values. The YAML 1.2.2 specification is the reference.

What formatting loses

Comments are not part of YAML's data model, so a parse and re-dump drops them, and anchors are expanded. Format a copy, or use a comment-preserving formatter such as yamlfmt or Prettier in a repository.

Share

Frequently asked questions

Why does my YAML file fail with mapping values are not allowed here?
A value contains a colon followed by a space, so the parser reads it as a nested key. Wrap the value in quotes.
Is JSON valid YAML?
Yes. YAML 1.2 is a superset of JSON, so any JSON document parses as YAML, which is why the formatter also accepts JSON input.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools