YAML Formatter & Validator - Format YAML Online
Fix YAML indentation without losing your comments, and get invalid YAML flagged with the exact line number. Converts to and from JSON too.
Formatted YAML will appear hereβ¦
Formatting runs on our servers, not in your browser. Avoid pasting credentials, personal data or anything else confidential.
What a YAML Formatter Should Do
YAML is the one common config format where indentation is the structure. Two spaces instead of four is not a style preference β it changes which block a key belongs to. That makes formatting YAML a different job from formatting Java or SQL: a tool that guesses wrong does not produce ugly output, it produces a different document.
This formatter reads the file first. It recovers each line's nesting depth from the original indentation, then re-emits the whole document at one consistent width. A file indented three spaces in one place and five in another comes out uniform, with the same meaning it went in with.
Before
# Service config
name: my-service
server:
host: localhost
tags:
- web
- apiAfter
# Service config
name: my-service
server:
host: localhost
tags:
- web
- apiYour Comments Survive
Most online YAML formatters parse the document into an object and print it back out. That produces tidy output and silently deletes every comment you wrote β which, in a file that is half explanation, is usually the worst possible outcome.
This one keeps them. Full-line comments are aligned with whatever they introduce, and trailing comments stay on their line. Block scalars (| and >) are copied through byte for byte, including the indentation inside the block, because there the whitespace is part of your value rather than part of the structure.
It Validates Before It Writes
Because the document is parsed before anything is emitted, unreadable YAML is rejected with the line number rather than reformatted into something that means something else:
- Tabs used for indentation β YAML forbids them, and most editors hide the difference
- A dedent that lines up with no open block β genuinely ambiguous structure
- The same key twice in one mapping β invalid per the spec, and a common merge artefact
- An unterminated quote
- An unclosed
[or{ - A mapping entry with no key
It reads structure, not meaning. It will not tell you that a port should have been a number rather than a string, and unrecognised tags or anchors are passed through untouched.
Where YAML Bites
Kubernetes
A manifest rejected for indentation you cannot see in the diff.
Docker Compose
Services quietly merged because a key was duplicated.
CI Pipelines
A GitHub Actions workflow that fails to parse on push.
Pasted Config
Snippets copied from docs or chat that lost their shape.
Merge Conflicts
Duplicate keys left behind after a botched resolution.
OpenAPI Specs
Deeply nested documents where the level is hard to track.
Sequences Get Nested
YAML lets you write a list at the same indent as the key that owns it, or indented under it. Both are valid and mean exactly the same thing, which is why the same repository often contains both. The formatter settles on the indented form:
tags: tags: - web β - web - api - api
YAML β JSON Conversion
The two conversion buttons run entirely in your browser β no round trip. They are useful for moving a config into an API payload, or for turning a JSON response into something readable. One caveat worth stating plainly: JSON has nowhere to put comments, so converting to JSON drops them. If you want your comments kept, use Format rather than convert. For working the other way, the JSON formatter handles payloads directly.
Formatting Is Idempotent
Running the formatter on its own output produces exactly the same text. That means the tool has one fixed idea of correct layout, so repeated use never drifts and formatted YAML committed to version control will not produce a spurious diff the next time somebody formats it.
Privacy and Limits
Formatting and validation run on our servers: your document is sent over HTTPS, processed, and returned. It is never shared with third parties or used for advertising. Even so, treat it as an upload β Kubernetes Secrets, API keys, database passwords and certificates do not belong in any online tool, this one included. Redact them first, or format a representative sample. Input is capped at 2 MB. The YAML β JSON conversion is the exception: it never leaves your browser.
Working with other formats too? The SQL formatter and Java formatter take the same conservative approach to code, and XML formatter covers the other config format you probably still have lying around.
β Frequently Asked Questions
What is a YAML formatter?
A YAML formatter rewrites the whitespace in a YAML file so its structure is obvious: one consistent indent per nesting level, sequences lined up under the key that introduces them, and no trailing whitespace. The data itself is unchanged.
Does it keep my comments?
Yes. Comments survive formatting β full-line comments are aligned with whatever they introduce, and trailing comments stay on their line. This matters more for YAML than any other format, since config files are mostly comments. Many YAML formatters parse to an object and re-emit, which silently deletes every comment.
Can it validate YAML?
Yes, and validation runs before anything is rewritten. If the document cannot be read you get the problem and the exact line number instead of a reformatted file that means something different.
What errors does it catch?
Tabs used for indentation, a dedent that lines up with no open block, the same key twice in one mapping, an unterminated quote, an unclosed [ or { bracket, and a mapping entry with no key. Each is reported as 'Line N: β¦'.
Why is my YAML invalid?
The most common causes are a tab character where spaces are required, indentation that does not line up with any enclosing block, and a duplicate key. The error message names the line so you can go straight to it.
Can I choose the indent width?
Yes. Pick 2 or 4 spaces before pressing Format. Two is the convention for Kubernetes, Docker Compose and GitHub Actions.
Does it handle block scalars?
Yes. The contents of | and > blocks are copied through byte for byte, including their internal indentation, because there the whitespace is part of the value rather than the structure.
Will it break my multi-line strings or URLs?
No. A colon only separates a key when a space or the end of the line follows it, so url: http://host:5432/db is left alone. Quoted strings are never reformatted.
Can I convert YAML to JSON?
Yes, in both directions, and the conversion runs entirely in your browser. Note that JSON has nowhere to put comments, so converting to JSON drops them β formatting keeps them.
What is YAML used for?
Configuration, mostly: Kubernetes manifests, Docker Compose files, GitHub Actions and other CI pipelines, Ansible playbooks, OpenAPI specifications and application config.
Is my YAML data secure?
Formatting and validation are done on our servers: your document is sent over HTTPS, processed, and returned. It is never shared with third parties or used for advertising. Because it does leave your browser, avoid pasting secrets β Kubernetes Secrets, API keys and passwords do not belong in any online tool. YAML to JSON conversion is the exception and runs locally.
Does it check my values are the right type?
No. It reads structure, not meaning. It will not tell you that a port should have been a number, and unrecognised tags or anchors are passed through untouched.
Is the formatting stable if I run it twice?
Yes. Formatting is idempotent β running it on its own output produces exactly the same text, so it is safe to use repeatedly or in a checked-in workflow.
Is this tool free?
Yes. It is completely free with no registration, and input is capped at 2 MB.
Which browsers support this tool?
It works on Chrome, Firefox, Safari, Edge, and all modern browsers, on desktop and mobile.