YAML Formatter & Validator
Check YAML for syntax errors and re-indent it consistently.
About YAML Formatter & Validator
A YAML formatter that checks a file for syntax errors, names the line and column of the first one, and rewrites valid YAML with even indentation.
How to use
- Paste YAML, or load a
.yamlor.ymlfile with the file picker or by dropping it on the page. - If the YAML is valid, a green note says so and counts the documents. If not, the error under the input gives the line, the column and the reason.
- Pick 2 or 4 spaces of indentation, and tick Sort keys alphabetically if you want a stable key order for diffs.
- Copy the result, or Download it as
.yamlnamed after the loaded file.
What it does
- Parsing is done by js-yaml with the YAML 1.2 core schema. Bad indentation, an unclosed quote or bracket, a tab used for indentation and a duplicated key are all reported as errors.
- Valid YAML is written back in block style: flow collections such as
{a: 1}and[x, y]are expanded to one entry per line, list items are indented under their key, and long strings are never wrapped. - A stream of several documents stays several documents, separated by
---. <<merge keys and aliases are kept, but anchors are renamed&ref_0,&ref_1and so on.- Values are rewritten in their plain form:
0o17becomes15,~becomesnull, double quotes become single quotes where quoting is still needed, and a folded>string becomes a literal|block.
What it does not do
- Comments are removed. The output is rebuilt from the parsed data, and comments are not part of it. The page says so when it sees a
#comment. To change indentation in a file whose comments matter, use your editor's formatter. - Blank lines between sections are not kept either.
- It checks syntax only. It does not know whether a Kubernetes manifest or a Compose file has the right fields.
Example
server: {host: localhost, port: 8080}
tags: [a, b]
→
server:
host: localhost
port: 8080
tags:
- a
- b
Privacy
Parsing and formatting run in the page. A loaded file is read locally, no request is made, and nothing is stored.
Frequently asked questions
- How do I check whether a YAML file is valid?
- Paste it into a parser and see whether it loads. This page does that in the browser: valid YAML gets a green note with the number of documents, and invalid YAML gets the line, column and reason for the first error. On the command line, python -c "import yaml,sys; yaml.safe_load(sys.stdin)" < file.yaml does the same job.
- Should YAML be indented with 2 or 4 spaces?
- Either is valid, as long as entries at the same level line up. Two spaces is the common choice for Kubernetes, Docker Compose, GitHub Actions and most other config files. Tabs are not allowed for indentation in YAML at all.
- Why does formatting remove my YAML comments?
- A formatter that parses YAML into data and writes it back has nowhere to keep comments, because they are not part of the data. That is how this tool and most library-based formatters work. If the comments matter, reindent in an editor, or use a formatter that edits the text in place, such as Prettier.
- What does "duplicated mapping key" mean?
- The same key appears twice in one mapping, for example two "image:" lines under the same service. The YAML specification requires keys to be unique, and parsers that tolerate duplicates silently keep only one of the values, so it is reported as an error. Remove or rename one of the keys.