What is YAML?
YAML (YAML Ain’t Markup Language) is a human-readable data serialization language that has become the standard for configuration files in modern DevOps and software development. Originally released in 2001, YAML was designed to be more readable than XML and simpler than JSON for configuration purposes.
YAML is used extensively in tools like Kubernetes, Docker Compose, Ansible, GitHub Actions, GitLab CI, and many other platforms. Its reliance on indentation rather than brackets or tags makes it visually clean, but also makes it sensitive to formatting errors.
How to Use the YAML Validator
- Paste your YAML content into the input area
- Click “Validate” or press
Ctrl+Enterto check syntax - Review any errors reported with line numbers
- Fix the issues and re-validate until your YAML is clean
The validator checks for the most common YAML issues: tab characters, inconsistent indentation, duplicate keys, malformed key-value pairs, and incorrect list syntax.
Common YAML Errors and How to Fix Them
Tab Characters
YAML strictly forbids tab characters for indentation. This is the single most common YAML error:
# Wrong (uses tabs)
server:
port: 8080
# Correct (uses spaces)
server:
port: 8080
Configure your editor to use spaces instead of tabs for YAML files. In VS Code, set "editor.insertSpaces": true and "editor.tabSize": 2 for .yml and .yaml files.
Inconsistent Indentation
All items at the same level must use the same number of spaces:
# Wrong
database:
host: localhost
port: 5432
# Correct
database:
host: localhost
port: 5432
Duplicate Keys
YAML doesn’t allow duplicate keys at the same level. The second value silently overwrites the first, which can cause hard-to-debug issues:
# Wrong - 'port' appears twice
server:
port: 8080
host: localhost
port: 3000
Missing Colon in Key-Value Pairs
Every key must be followed by a colon and a space:
# Wrong
name John
# Correct
name: John
YAML vs JSON
| Feature | YAML | JSON |
|---|---|---|
| Readability | More readable | More verbose |
| Comments | Supported (#) | Not supported |
| Indentation | Significant | Not significant |
| Data types | Auto-detected | Explicit |
| Trailing commas | Not applicable | Not allowed |
| Multi-line strings | Native support | Requires \n |
YAML is generally preferred for configuration files that humans edit frequently, while JSON is better suited for data exchange between systems and APIs. Many tools accept both formats.
YAML Best Practices
Use Consistent Indentation
Pick 2 spaces per level (the most common convention) and stick with it throughout your project. Configure your editor and linter to enforce this.
Quote Strings When Ambiguous
YAML auto-detects types, which can cause surprises. Values like yes, no, true, false, null, 1.0, and 3:00 are interpreted as booleans, null, floats, or sexagesimal numbers:
# Dangerous - interpreted as boolean true
country: Norway
uses_yaml: yes
# Safe - explicitly a string
country: "Norway"
uses_yaml: "yes"
Use Linting in CI/CD
Add YAML linting to your CI/CD pipeline using tools like yamllint. This catches formatting issues before they cause deployment failures. A misconfigured YAML file in Kubernetes or Docker Compose can bring down your entire infrastructure.
Validate Before Deploying
Always validate YAML configuration files before applying them to production systems. This online validator provides instant feedback, but for automated workflows, integrate a YAML linting step into your build pipeline.