YAML Formatter
Paste YAML and get it laid out consistently: your choice of indent, block or flow collections, keys sorted or left alone. Multi-document streams stay multi-document. Date-shaped values stay strings rather than becoming timestamps, and a ZIP code of 01730 keeps its leading zero, which is where most YAML round trips quietly lose data.
Try an example loads a config with anchors, a date, a padded number and the classic yes trap in it.
The three values YAML silently ruins
YAML's type inference is famously generous, and a naive round trip through a parser and a writer changes data. Three cases account for nearly all of it, and all three are handled here.
| You wrote | A careless round trip gives | This page gives |
|---|---|---|
created: 2024-01-15 | a timestamp object, re-serialized as 2024-01-15T00:00:00.000Z | created: "2024-01-15" |
zip: '01730' | zip: 1730, the leading zero gone | zip: "01730" |
enabled: yes | enabled: true, in YAML 1.1 | enabled: "yes" or true, depending on what it parsed as |
The reading side uses the YAML Core Schema, which is what keeps 2024-01-15 a string rather than promoting it to a date. The writing side quotes anything a YAML 1.1 reader would misinterpret, so the value survives whatever reads the file next.
That is why a date comes back quoted rather than bare. It looks like an unnecessary change and it is the opposite: the quotes are what stop the next tool in the chain turning your date into something else.
Multi-document streams stay streams
A YAML file can hold several documents separated by ---. Every Kubernetes manifest set is one, and so is most of what helm template produces. A formatter that loads the file and dumps the first document destroys the rest, silently, and you find out at kubectl apply time.
Here each document is formatted on its own and the separators are put back. The count is reported in the summary and a note names it, because "this is a 6-document stream" is worth knowing before you go looking for the deployment you cannot find.
Anchors are expanded, and it says so
YAML anchors let one block be defined once and referenced elsewhere. Merge keys go further and splice a mapping into another:
defaults: &defaults
retries: 3
timeout: 30
env:
<<: *defaults
region: eu-west-1
Reading this resolves the merge, so env genuinely has retries, timeout and region in it. Writing it back out writes them all, because reconstructing which keys came from an anchor is not something a value can tell you.
The result means exactly the same thing and is longer. A note says so, so the change is never a surprise. If keeping the anchors matters more than the formatting, this is the page to skip.
The options
- Indent: two or four spaces. Two is the near-universal convention and the default.
- Collections: block or flow. Block is the multi-line form everybody writes. Flow puts lists and maps inline as
[a, b]and{k: v}, which is compact and occasionally what a tool wants. - Sort keys A to Z: recursive, so nested maps are sorted too. List order is never touched, because a list's order is data. This is what makes two config files diffable when they hold the same settings written in different orders.
- Quote every string: for a file heading somewhere strict, or where you want to remove any possibility of a reader inferring a type.
- Wrap long lines: at 100 characters, or never. Never is the right choice for a file holding long URLs or base64 blocks, where a wrapped line is harder to grep and harder to copy.
The summary reports the document count and the total key count across all of them, which is a quick sanity check that the output holds what the input did.
What people bring here
- A CI file that four people have edited with three different indent settings.
- A Kubernetes manifest pasted out of a terminal with the indentation half-eaten.
- Two config files that should be identical, sorted so a diff shows the real differences rather than ordering noise.
- Something generated by a tool that emits valid but unreadable YAML, usually with flow collections everywhere.
- A file that will not parse, where the error message and its line number are the whole reason for the visit.
That last case gets a real message. A YAML parse error names the line and column and quotes the offending snippet, rather than reporting that something somewhere is wrong.
Frequently Asked Questions
Why did my date come back in quotes?
To protect it. Unquoted, 2024-01-15 is a timestamp to a YAML 1.1 reader and a string to a YAML 1.2 one, and you cannot control which one reads your file next. Quoting pins it as the string you wrote. The value is unchanged; only its protection is added.
Does it keep my comments?
No, and this is the honest limitation of the page. YAML comments are not part of the data model, so a parse-and-write round trip loses them. Every YAML formatter built this way has the same behavior. If comments are load-bearing in your file, re-indent it by hand instead.
Will it break my multi-document Kubernetes file?
No. Each document is formatted separately and the --- separators are put back, with the document count reported in the summary and a note. Losing every document after the first is a real failure mode in other tools and it is specifically guarded against here.
What happens to my anchors and merge keys?
They are resolved and written out in full. The output means the same thing and is longer. A note tells you it happened, because it is a visible change to a file you may have deliberately factored.
Should I sort the keys?
Sort them when you are about to diff two files that should agree, because ordering noise is most of what makes such a diff unreadable. Leave the order alone when the file is one people edit, since a hand-maintained config usually groups related settings for a reason.
Can I convert rather than format?
Yes, elsewhere on the site: JSON to YAML, YAML to JSON and YAML to CSV. All three share this reader, so the same protections apply.
Does anything I paste leave my computer?
No. There is no upload endpoint on this page and no network request in the code that does the work. JavaScript in your own tab reads the text, processes it and hands back the result. Nothing is stored between visits either, so reloading gives you an empty box again. You can confirm it by opening your browser's network panel and watching it stay quiet while you work.
Tidy YAML that still means what it said
Free, no account, no upload. Streams kept, dates kept, leading zeros kept.
Back to the formatter