Developer Tools

YAML Formatter & Validator

Tidy YAML without changing what it says.

  • Runs in your browser
  • Free, no signup

Paste YAML to tidy it, compact it or check it. The document is parsed properly and re-emitted, so the structure that comes out is the one that went in. Nothing is uploaded — the parsing happens in this page.

Parsed with js-yaml, vendored into this site rather than loaded from a CDN, so your document is never sent to a third party. YAML anchors and aliases are resolved, which means a short document can expand into a large one — the size of the expansion is checked, not just the size of what you pasted.

Up to 2 MB. Pasting something larger is refused rather than quietly freezing the tab.

YAML cannot be indented with tabs, so the tab option is offered only for alignment of the block scalars it can carry. Stick to spaces if the file will be read by another YAML parser.

Your document is parsed and formatted in this browser by js-yaml, which is served from this site rather than a CDN. Nothing is sent to this site or to any third party.

YAML is written to be read by people, and it fails for the same reason. Indentation is the structure, so a file that is one space out is not badly formatted — it is a different document, and sometimes a valid one that means something else entirely. That is the difference between a formatter and a prettifier.

This page parses your YAML into a document and writes it back out, so what comes out is the same document by construction rather than by careful pattern matching. Block scalars, anchors, aliases and multi-line strings are handled by the parser, not by a regular expression over the lines.

How to use this tool

  1. Paste YAML into the box, or press Example for a document that uses nesting, a list and a block scalar.
  2. Press Format to tidy it, Compact for the flow-style form, or Validate to check it without producing output.
  3. If it will not parse, the line and column are reported along with the parser's own description of the problem.

Why it parses rather than reindents

A formatter that reindents by pattern has no idea whether a line is a mapping key, part of a block scalar, or the beginning of a flow sequence that continues for another four lines. Block scalars (`|` and `>`) are the clearest case: their content is raw text whose indentation is significant, and a formatter that reformats it has changed the document.

Parsing also means the errors are real errors with positions, rather than a formatter's guess at what looks wrong. The parser decides whether the document is valid; this page only decides how to lay out what it produced.

YAML to JSON

YAML's data model is JSON's — mappings, sequences and scalars, with more ways of writing them down. That makes the conversion exact, and the As JSON button uses the document that was already parsed rather than parsing it a second way.

The reverse is not offered, and that is deliberate. JSON has no comments, no anchors, no block scalars and no multi-line strings, so turning JSON back into YAML means inventing style choices that were never in the original. If you need that, write the YAML.

Anchors, aliases and how the size is judged

Anchors and aliases let one document refer to a value defined elsewhere in it. They are resolved when the document is read, so a few hundred bytes can expand into a great many values — and the anchors are written back out when the result is produced, which means the anchor names may differ from the ones you wrote.

Because a small file can expand hugely, the limit here is not just the size you pasted. The number of values in the parsed document is counted, and a document that expands beyond that bound is refused rather than frozen on.

Frequently asked questions

Is my YAML sent anywhere?

No. It is parsed and formatted in your browser by js-yaml, which is served from this site rather than loaded from a CDN. Nothing is sent to this site or to any third party.

Will formatting change my block scalars?

No. Block scalar content is text whose indentation is part of its value, and it is carried through as it was written. Only the structure around it is laid out.

Why did my anchor names change?

The document is re-emitted from the parsed structure, and the parser names anchors itself. The references and the meaning are preserved; the labels may not be the ones you chose.

Can a tab be used for indentation?

Not in YAML — a tab where indentation is expected is an error, and the parser will say so. Use spaces; the tab option here is for the JSON output, where it is allowed.

What does Compact do?

YAML has no minified form, because the block style needs line breaks to mean anything. Flow style — braces and brackets on one line — is the closest equivalent, and that is what Compact produces.