How to validate YAML
- Paste YAML or open a
.ymlor.yamlfile. It is checked as you type; Validate (Ctrl + Enter) opens the Report tab. - An error shows the line and column, the code around it and a Fix: hint. Go to error jumps there.
- Format re-indents with 2 or 4 spaces (Indent). The Tree tab shows how each value is read.
Example: a key indented under a value
server:
host: 0.0.0.0
port: 8080
logging:
level: info
format: json
The report says Line 6 is indented under a value, so it cannot start a new key. and suggests lining it up with the key on line 5.
Other messages
| Mistake | Message |
|---|---|
| A tab used for indentation | Tabs are not allowed for indentation. |
| The same key twice in one mapping | Duplicate key. |
title: Note: read this first |
Nested mappings are not allowed in compact mappings, with a hint to quote values that contain : |
name: "web with no closing quote |
Missing closing "quote |
user: @admin |
Plain value cannot start with reserved character @ |
Format keeps comments
app: billing # service name
replicas: 3
env:
- name: LOG_LEVEL
value: "debug" # temporary
Format with 2 spaces:
app: billing # service name
replicas: 3
env:
- name: LOG_LEVEL
value: "debug" # temporary
Key order and quote style survive too; only spacing changes.
What the YAML validator does not check
It checks syntax (indentation, quotes, brackets, duplicate keys) in every document of the file, not style rules such as line length or a leading ---, which is yamllint’s job. It also does not know the schema of a Kubernetes manifest or a GitHub Actions workflow, so a misspelled field passes: convert the file with YAML to JSON and test it in the JSON Schema validator. To write YAML from JSON, use JSON to YAML.