YAML Validator & Formatter
FormatValidate, normalise or compress YAML with js-yaml. Tidies indentation and quote style, and splits multi-document (---) streams. Pure YAML processing — no format conversion.
Remote URLs are not fetched; paste your JSON directly.
On this page
What is a YAML formatter?#
A YAML formatter takes a config file that has drifted — tabs mixed with spaces, inconsistent indent step, quotes used in some places and not others, an anchor someone defined and never reused — and normalises it into a clean, predictable shape. It also catches the thing YAML is notorious for: a document that looks fine and quietly means something else, because YAML is whitespace-significant and full of implicit rules about what a bare word means.
This page parses your YAML and re-emits it through js-yaml in a controlled way. Format re-indents with the step you choose (2 or 4 spaces), turns off line folding so each value sits on its own line, and expands any anchors and aliases into plain repeated content so the output is fully self-contained. Minify re-dumps the same data in flow notation — {a: 1, b: [2, 3]} — which is the closest YAML has to a compact form, since YAML cannot just delete its whitespace the way JSON or CSS can. Whichever mode you pick, the document is parsed first, so a tab where a space should be or a colon missing its trailing space is reported with its row and column instead of silently producing the wrong data structure.
How to use it#
- Paste your YAML into the Input pane on the left. The placeholder shows a minimal document, or click Sample.
- Pick a Mode button on the toolbar:
- Format — re-indent, disable line folding, expand anchors/aliases, and emit each collection in block style.
- Minify — emit every collection in flow style on as few lines as possible. Indentation becomes irrelevant because flow collections are explicit.
- In Format mode, choose an Indent: 2 or 4 spaces.
- Optionally choose a Quote style: auto (quote only when a scalar actually needs it — the default), single, or double. This normalises the quote character on scalars that must be quoted; it never forces quotes onto plain values that do not need them.
- Read the result in the Output pane. The header shows the output size; use Copy to take it. Clear resets both panes.
If parsing fails, the status bar reports the row and column of the problem — YAML errors from js-yaml carry a position, and this page surfaces it directly.
Key features#
- Format and minify from the same parse. Both modes validate the document up front, so a structural error is reported once with a location, regardless of which button you pressed.
- Anchors expanded.
&anchor/*aliasreferences are resolved and written out inline (noRefs), so the output never depends on a name defined three screens earlier. The result is a self-contained document you can hand to anyone. - No line folding. Long values are not wrapped at a column limit (
lineWidth: -1), so each value occupies exactly one line — easier to diff and easier to read. - Optional quote normalisation. Pick single or double quotes to make the quote character consistent across the document, or leave it on auto so only the values that genuinely need quoting get it.
- Multi-document aware. Input separated by
---is parsed as multiple documents and re-emitted with---separators intact — handy for Kubernetes manifests and similar multi-doc files. - Defends against YAML bombs. A nesting-depth cap keeps pathologically deep documents from expanding into something dangerous.
- Strictly client-side, with a Web Worker for inputs over 1 MB so the page stays responsive.
Worked example#
A service config with a reused anchor and slightly uneven style:
Input:
service:
name: &name "api-gateway"
host: example.com
replicas: 3
id: *name
logging:
level: info
outputs: [{name: stdout}, {name: file}]
Click Format with 2 spaces and auto quotes:
service:
name: api-gateway
host: example.com
replicas: 3
id: api-gateway
logging:
level: info
outputs:
- name: stdout
- name: file
Two things happened that you can see. The anchor &name and alias *name were both resolved to the literal value api-gateway, so id now reads as a plain value and the document no longer depends on the anchor. And the flow-style list [{name: stdout}, {name: file}] was rewritten as a block list, one entry per line — much easier to scan and to diff against another version. Click Minify on the same input and the same data comes back in flow form:
service: {name: api-gateway, host: example.com, replicas: 3, id: api-gateway}
logging: {level: info, outputs: [{name: stdout}, {name: file}]}
Every collection is now inline. The byte count drops because indentation and newlines are gone, but the meaning is identical — which is exactly what minify should mean for a whitespace-significant format.
FAQ#
Where did my comments go?#
YAML round-tripping through js-yaml parses comments and discards them — there is no comment-preserving re-dumper in the library. Comments are tolerated during parsing (they never cause an error) but they do not appear in the output. If comments carry important context, keep your original file as the source of truth and treat this tool’s output as the canonical machine form.
What is the difference between Format and Minify for YAML?#
Format rewrites the document in clean block style: nested mappings and sequences indented with the step you chose, one value per line, no folding. Minify rewrites the same data in flow style: {key: value} and [a, b] collections on a single line. Both parse identically first; they only differ in how the data is serialised back out.
How is this different from the YAML/JSON converter?#
This tool is YAML in, YAML out — it normalises or compacts a YAML document and hands back YAML. The YAML/JSON converter on this site translates between the two formats. Use this page when you want the same format, just shaped better; use the converter when you actually want JSON.
Is my YAML uploaded anywhere?#
No. js-yaml is bundled into the page and runs in your browser. For inputs over 1 MB the parse happens inside a Web Worker, but still locally — nothing leaves your device.