What is a YAML validator?
A YAML validator parses a YAML document and reports whether it follows the YAML 1.2 specification, and if not, where and why it fails. Because YAML uses indentation and a few punctuation marks for structure, most errors come from whitespace and are hard to see. This validator gives the line and column of every error, a plain explanation, the parser's own message for reference, and hints for the most common causes.
How to validate YAML
- Paste YAML or open a file; it is checked while you type.
- Read the status line: green for valid (with the number of documents, keys and nesting depth), yellow when there are warnings, red for errors.
- Click a problem to jump to it in the editor.
- When it is valid, format it or convert it with YAML to JSON.
Common YAML errors
| Problem | Example | Fix |
|---|---|---|
| Tab used for indentation | ␉image: nginx | Indent with spaces only |
| No space after the colon | replicas:3 | replicas: 3 |
| Inconsistent indentation | a key indented 3 spaces under siblings at 2 | Align it with its siblings |
| Unclosed flow collection | ports: [80, 443 | ports: [80, 443] |
| Value starting with a reserved character | user: @admin | user: "@admin" |
| Duplicate key | name: a … name: b | Keep one of them |
| Alias to an undefined anchor | <<: *defaults without &defaults | Define the anchor above |
YAML 1.1 pitfalls the linter warns about
These values are valid, but they mean different things depending on the parser. YAML 1.2 (used by this tool and by modern libraries such as eemeli/yaml and Go's yaml.v3) reads them one way; YAML 1.1 parsers such as PyYAML, Ruby's Psych and Go's yaml.v2 read them another way. Quoting them makes every parser agree.
- yes / no / on / off / y / n: strings in 1.2, booleans in 1.1. The classic example is the country code
NO. - Leading zeros such as
0755or a ZIP code02134: the leading zero is dropped, and 1.1 parsers read the value as octal. - Colon-separated numbers such as
22:22in a port mapping: a base-60 integer in YAML 1.1, which is why Docker documentation tells you to quote ports. - Version-like decimals such as
3.10: a float, so the version becomes 3.1.
Example
spec:
replicas:3
template:
spec:
containers:
- name: web
image: nginx
The validator reports that line 2 has no space after the colon, so YAML reads replicas:3 as one string, and that line 7 uses a tab for indentation. Fix both and the document parses.