YAML Formatter and Validator
Part of Text tools: See all Text tools.
What is YAML Formatter?
YAML Formatter checks and tidies YAML you paste. Validate tells you whether the YAML parses and how many documents it holds, or gives the line and column of the first error. Format rewrites it with consistent two-space indentation, one item per line. Compact (one line) turns each document into a single flow-style line. Convert to JSON gives you the same data as indented JSON. Because JSON is valid YAML, you can also paste JSON and click Format to get YAML. Files with several documents separated by --- are supported. Everything runs in your browser.
How to use YAML Formatter
- Paste your YAML into the input box. To turn JSON into YAML, paste the JSON instead.
- Tick Sort keys A to Z if you want every mapping in alphabetical order; otherwise the original key order is kept.
- Click Validate to check the syntax, Format to re-indent, Compact (one line) for flow style, or Convert to JSON.
- Read the status line under the buttons: it shows the document count, the line and column of any error, and warnings about comments or long numbers. Then use Copy result or Download.
Why use this tool?
YAML depends on indentation, so a single tab, a stray space or a repeated key can break a Docker Compose file, a Kubernetes manifest or a CI workflow, and the error you get at deploy time is often vague. Running the file through a parser first points to the exact line, and re-indenting it makes nesting mistakes easy to see. Converting to JSON is handy when an API or script wants JSON, or when you want to see exactly how a value was read.
YAML Formatter — In-Depth Guide
YAML is the format behind most configuration files in modern development: Docker Compose, Kubernetes manifests, Helm values, GitHub Actions and GitLab CI workflows, Ansible playbooks and many app settings files. It is easy to read, but its structure comes from indentation, so problems are often invisible. A tab instead of spaces, a list item indented one space too far, or the same key written twice can all change the meaning of a file or stop it from loading.
The quickest check is Validate. It parses the whole file and either confirms it, with the number of documents found, or stops at the first error and tells you the line and column. Common messages are "bad indentation of a mapping entry" (a key is not lined up with its siblings), "duplicated mapping key" (the same key appears twice in one block) and "tab characters must not be used in indentation". Fix the first error and validate again, because one mistake can hide others below it.
Format rewrites the file in a consistent style: two-space indentation, one list item per line, block style for nested data and the original key order unless you tick Sort keys. Long strings are left on one line, and multi-line text written with | keeps its line breaks. Formatting is not lossless, though: comments are removed and quoting may change, so treat the output as a clean copy rather than a drop-in replacement for a heavily commented file. Compact does the opposite and writes each document on a single line in flow style, which is useful for pasting a small structure into a command or a message.
Tip: if a value must stay exactly as typed, quote it. That applies to version numbers like "3.10" (otherwise read as the number 3.1), IDs with 16 or more digits (otherwise rounded), values with a leading zero like "0755", and words like "no" when the file will be read by an older YAML 1.1 tool. For JSON files use the JSON Formatter, and to see what changed between two versions of a config file use Text Diff.
Why YAML breaks in ways JSON never does
YAML was designed to be human-friendly — no braces, no quotes around most strings, structure expressed through indentation rather than punctuation. That friendliness is also its curse. Because indentation is the syntax, a single misplaced space, a tab where spaces were expected, or one key nested a level too deep changes the meaning of the document or breaks it entirely, and the error is often invisible to the eye. A JSON file with a missing brace fails loudly and obviously; a YAML file with a subtly wrong indent frequently parses into the wrong structure without complaint, which is far more dangerous. A formatter and validator exists to make these invisible errors visible before they reach a server.
The errors that actually bite
A handful of mistakes account for most YAML pain. Tabs. YAML forbids tab characters for indentation, and since tabs and spaces look identical on screen, a single tab pasted from another editor produces a baffling parse error. Inconsistent indentation. Mixing two-space and four-space indents within the same file, or misaligning a list item by one space, silently reparents your data. Duplicate keys. Defining the same key twice in a mapping is usually a copy-paste accident, and most parsers quietly keep only the last one, so a setting you carefully wrote is simply ignored. Unquoted special values. The strings yes, no, on, off, and null get interpreted as booleans or null unless quoted — so a country code NO (Norway) becomes the boolean false. Validating catches all of these; reformatting prevents most of them recurring.
What "formatting" does for you
Reformatting takes YAML that parses — even if it is inconsistently indented or chaotically spaced — and rewrites it with uniform, predictable indentation at the depth you choose (two or four spaces). This does more than make it pretty. Consistent formatting makes structural mistakes visible: when every level is reliably indented the same amount, a key that is nested wrong jumps out because it sits at the wrong column. It also produces clean diffs in version control, so when you commit a config change, the diff shows your actual change rather than a storm of whitespace noise. Clean, consistent YAML is easier to review, and easier-to-review config is config with fewer production incidents.
Where this matters most: infrastructure config
YAML's biggest modern role is configuring infrastructure — Kubernetes manifests, Docker Compose files, CI/CD pipeline definitions, Ansible playbooks. These are exactly the files where a silent indentation error is most expensive, because the failure shows up not in your editor but in a failed deployment, a container that will not start, or a pipeline that runs the wrong steps. Validating a Kubernetes manifest locally before kubectl apply turns a confusing cluster error into an obvious line-number error you can fix in seconds. The earlier in the loop you catch a YAML mistake, the cheaper it is, and a quick validate-and-format pass is the earliest point available.
Reading the validation feedback
When validation flags an error, the line and column it reports is where the parser noticed the problem, which is not always where the problem is. An indentation error is frequently caused a line or two above the reported line — a key that opened a block at the wrong depth throws off everything beneath it. So when you get an error, look at the reported line and the few lines before it. Fix the highest-up problem first and re-validate, because one structural mistake often cascades into several reported errors that all vanish once the root cause is corrected.
A safe editing habit
The reliable workflow for any non-trivial YAML edit is: make your change, format, validate, and only then deploy. Configure your text editor to insert spaces rather than tabs and to show whitespace, which eliminates the tab problem at the source. Quote any value that could be mistaken for a boolean, number, or null when you mean it as a literal string. And when a file has grown large and tangled, a single reformat pass to normalise its indentation is often the fastest way to make a lurking structural bug obvious. If your config is actually JSON rather than YAML, our JSON formatter does the equivalent validate-and-beautify job for that format.
Frequently asked questions
- Does it validate YAML or only reformat it?
- Both. Every button parses the YAML first. If parsing fails you get the line, the column and the reason, for example "duplicated mapping key" or "tab characters must not be used in indentation", and nothing is reformatted.
- Are my comments kept?
- No. The parser reads the data, not the comments, so Format, Compact and Convert to JSON all drop them. The status line warns you when your input looks like it had comments. Keep your original file if the comments matter.
- Can it handle files with several documents separated by ---?
- Yes. Each document is parsed and formatted separately and the output keeps the --- separators. Convert to JSON returns one JSON array with one item per document.
- Can I convert JSON to YAML or YAML to JSON?
- Yes. Paste JSON and click Format to get YAML, or paste YAML and click Convert to JSON. Dates such as 2026-10-20 stay as plain text in both directions, and .inf or .nan values become null in JSON because JSON has no such numbers.
- Which YAML version does it follow?
- YAML 1.2 (the core schema of the js-yaml library). That means yes, no, on and off stay text instead of turning into true or false, and a number with a leading zero such as 0755 is read as decimal 755. Quote values like that if your tool expects YAML 1.1 behaviour. Strings that older parsers might misread, such as 'yes' or '3.8', are written with quotes.
- What about anchors, aliases and merge keys?
- They are kept. Anchors are renamed to ref_0, ref_1 and so on, and <<: *anchor merge keys stay as merge keys rather than being expanded. Custom tags such as CloudFormation !Ref or GitLab !reference are not supported and show an error.
- Is my YAML uploaded?
- No. Parsing and formatting run in your browser with the open-source js-yaml library. The page loads that library from a public CDN, but your text is never sent anywhere.
Also try
Related tools that work well with this one: