Skip to main content
YF

YAML Formatter & Validator

Re-indent YAML to clean 2-space formatting and check it for syntax errors, right in your browser.

Did you like the tool? Thanks!
Share:


    

How to Use YAML Formatter & Validator

Paste any YAML document into the box and click "Format" to re-serialize it with consistent 2-space indentation, or click "Validate" to parse it and see whether it is well-formed (with a line number for the first problem found, where possible). Nothing you paste is uploaded anywhere — the parser runs entirely in JavaScript on your device.

About YAML Formatter & Validator

YAML ("YAML Ain't Markup Language") is a human-readable data format used for configuration files across almost every modern developer tool — Docker Compose, Kubernetes manifests, GitHub Actions workflows, Ansible playbooks, and countless application config files all use it. Its appeal is that it reads almost like plain English: indentation defines structure instead of the braces and brackets JSON needs, so a YAML file tends to be shorter and easier to skim than the equivalent JSON. That same reliance on whitespace is also YAML's biggest source of bugs. Because indentation is meaningful, a single misplaced space can silently change what a key belongs to, or break parsing outright. Tabs are not permitted for indentation in standard YAML (only spaces), and mixing tab and space indentation is one of the most common causes of "why won't my CI pipeline parse this file" bug reports. This formatter re-indents a document to a clean, consistent 2-space standard, which both fixes cosmetic inconsistency (mixed 2-space and 4-space blocks in a file edited by different people) and, as a side effect of round-tripping through a parser, surfaces structural mistakes that were previously hidden by inconsistent whitespace. This tool implements a lightweight, hand-rolled YAML parser and serializer covering the constructs people actually hit day to day: nested mappings (key: value blocks), sequences (- item lists, both block style and inline flow style like [a, b, c]), scalar values (strings, numbers, booleans, null), inline flow mappings ({a: 1, b: 2}), and quoted strings (both single and double quotes, including escaped characters in double-quoted strings). It deliberately does not implement the full YAML 1.2 specification — in particular it does not support anchors and aliases (&anchor / *alias), custom tags (!!type), multi-document streams (--- separators for multiple documents in one file), folded/literal block scalars with all their chomping-indicator edge cases (| and > with +/- modifiers), or merge keys (<<:). If a document uses any of these, format/validate may report an error or produce an approximation rather than a byte-perfect equivalent — for those advanced features, a dedicated YAML library (like js-yaml) is the right tool, and this widget will say so clearly if it hits a construct it does not recognise. There is no "minify" concept for YAML in the way there is for JSON or CSS, because YAML's structure depends on line breaks and indentation — removing them would either produce invalid YAML or force a switch to YAML's alternative "flow" syntax (the JSON-like {}/[] form), which is really a different serialization rather than a compressed version of the same one. Rather than bolt on a confusing pseudo-minify button, this tool offers exactly two actions: Format (pretty, block-style, 2-space indent) and Validate (parse and report errors) — both fully useful, neither pretending to be something it is not. The validator reports the first parsing problem it encounters together with the line number where it occurred, which is normally enough context to find and fix the issue (an unclosed quote, an unexpected indent level, a list item at the wrong depth). Because everything happens client-side, you can safely paste real configuration files — including ones with secrets in them for a quick formatting check — without that content ever leaving your browser tab.

Details & Tips

What this tool supports: block mappings (key: value, including nested mappings by indentation), block sequences (- item, including sequences of mappings), inline/flow sequences ([1, 2, 3]) and flow mappings ({a: 1, b: 2}), single- and double-quoted scalars (with standard escapes in double quotes), unquoted scalars with automatic type detection (true/false/null/numbers stay unquoted on output; strings needing quotes because of special characters get quoted), and full-line and trailing # comments (comments are recognised so they do not break parsing, but see the note below on comment handling). What this tool does NOT support (by design — this is a lightweight parser, not a full YAML 1.2 implementation): anchors and aliases (&x / *x), custom/explicit tags (!!str, !!int, custom tags), multi-document files (--- and ... document markers), literal and folded block scalars (| and > style multi-line strings) with their chomping indicators, merge keys (<<:), and complex (non-scalar) mapping keys. If your document uses any of these, Validate may report an error at the offending line, or Format may not round-trip it perfectly — check the output carefully before relying on it for anything that will be committed back to a real config file. A note on comments: because re-serializing a parsed data structure back into YAML discards anything that was not part of the actual data (this is inherent to a parse → rebuild round trip, not specific to this tool), comments are consumed during parsing to keep the parser working correctly, but they are not reproduced in the formatted output. If you need to preserve comments exactly, use Validate only, or format smaller, comment-free sections at a time. Worked example — messy input: ``` name: MyApp config: debug: true ports: - 80 - 443 ``` Formatted output (clean 2-space indent): ``` name: MyApp config: debug: true ports: - 80 - 443 ``` Validate mode reports issues like an inconsistent indent (a nested key indented by an odd, ambiguous number of spaces relative to its parent) or an unclosed quoted string, along with the 1-based line number where parsing broke down, so you can jump straight to the problem in your editor.

Frequently Asked Questions

Does this YAML formatter support anchors and aliases?
No. Anchors (&name) and aliases (*name) are part of the full YAML specification but are not implemented in this lightweight parser. Documents using them may fail validation or format incorrectly.
Why is there no "minify" button for YAML?
YAML relies on line breaks and indentation to represent structure, so it cannot be compressed onto one line the way JSON or CSS can without changing to a different syntax entirely (YAML's flow style). This tool offers Format and Validate instead.
Will formatting preserve my comments?
No. Formatting works by parsing your YAML into a data structure and then re-serializing it, and comments are not part of that data structure, so they are dropped in the formatted output. Use Validate if you need to check a file without losing comments.
Does this tool support multi-document YAML files (separated by ---)?
No, only single-document YAML is supported. Multi-document streams will likely fail to parse correctly.
Can I format YAML that uses tabs for indentation?
Standard YAML does not permit tabs for indentation, and this tool follows that rule — tab-indented input is likely to be reported as invalid. Convert tabs to spaces first.
Does the validator tell me exactly what is wrong?
It reports the type of problem (such as an unclosed quote or an inconsistent indent level) together with the line number where parsing failed, which is usually enough to locate and fix the issue in your editor.
Is my YAML content uploaded to a server?
No. Parsing, formatting and validation all happen locally in your browser using JavaScript. Nothing you paste is sent anywhere, which makes it safe to check files that contain sensitive configuration values.
Does it support literal and folded block scalars (| and >)?
No, multi-line block scalar styles are not supported by this lightweight parser. Use a full YAML library such as js-yaml if your documents rely on them.
What indentation does the formatter use?
A fixed 2-space indent per nesting level, which is the most common convention in YAML style guides and matches what tools like Kubernetes and Docker Compose documentation use.
Can I format inline flow-style YAML like {a: 1, b: 2}?
Yes, flow mappings and flow sequences are parsed correctly and will be expanded into block style in the formatted output.
Why did Validate say my YAML is invalid when a YAML linter elsewhere accepted it?
This is a lightweight parser covering common YAML constructs, not the full YAML 1.2 spec. If your file uses anchors, tags, merge keys or multi-document syntax, a full-spec parser may accept it while this tool does not.

Also Available As

yaml formatter, yaml validator, yaml pretty print, yaml linter, format yaml online, yaml indent fixer, yaml syntax checker

Found a Problem?

Let us know if something with YAML Formatter & Validator isn't working as expected.

Thanks — we'll take a look.