Last updated
YAML Validator Examples
The YAML Validator checks your YAML documents for syntax errors, indentation problems, duplicate keys, and type issues. Below are examples of common YAML mistakes and what valid YAML looks like.
Valid YAML — Basic Structure
A well-formed YAML configuration file:
server:
host: localhost
port: 8080
debug: false
database:
url: jdbc:postgresql://localhost:5432/mydb
username: admin
pool:
min: 2
max: 10
features:
- authentication
- logging
- caching
Validator result: Valid YAML. No errors found.
Indentation Error
Inconsistent indentation breaks YAML parsing:
server:
host: localhost
port: 8080 # ERROR: over-indented
Validator output:
Error at line 3, column 5:
Mapping values are not allowed here.
Expected indentation of 2 spaces, found 4.
Fixed version:
server:
host: localhost
port: 8080
Tab Character Error
YAML requires spaces for indentation — tabs are not allowed:
server:
host: localhost # ERROR: tab character used
Validator output:
Error at line 2, column 1:
Tab characters are not allowed for indentation.
Replace the tab with spaces.
Fixed version (using 2 spaces):
server:
host: localhost
Duplicate Key Detection
Duplicate keys in a mapping are invalid:
database:
host: localhost
port: 5432
host: remoteserver # ERROR: duplicate key
Validator output:
Warning at line 4:
Duplicate key "host" found in mapping.
First occurrence at line 2. Last value will be used.
Missing Colon
A missing colon after a key is a common typo:
app
name: my-service # ERROR: missing colon after "app"
Validator output:
Error at line 1:
Could not find expected ':' after key "app".
Kubernetes Manifest Validation
A valid Kubernetes Deployment manifest:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
labels:
app: web
spec:
replicas: 2
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.25
ports:
- containerPort: 80
Validator result: Valid YAML. Parsed structure shown in the output panel.
Multi-line String Validation
Both block scalar styles are valid:
# Literal block (preserves newlines)
description: |
This is line one.
This is line two.
# Folded block (newlines become spaces)
summary: >
This long text will be
folded into a single line.
Anchor and Alias Validation
Anchors and aliases must reference defined anchors:
defaults: &defaults
retries: 3
timeout: 30
service_a:
<<: *defaults
name: service-a
service_b:
<<: *defaults
name: service-b
Validator result: Valid. Anchors resolved correctly.
Invalid alias (referencing undefined anchor):
service:
<<: *undefined_anchor # ERROR
Validator output:
Error at line 2:
Alias "*undefined_anchor" references an undefined anchor.
Docker Compose Validation
Valid Docker Compose file:
version: "3.8"
services:
web:
image: nginx:latest
ports:
- "80:80"
depends_on:
- db
db:
image: postgres:15
environment:
POSTGRES_DB: appdb
POSTGRES_USER: admin
POSTGRES_PASSWORD: secret
volumes:
- db_data:/var/lib/postgresql/data
volumes:
db_data:
Common Validation Errors Summary
- Indentation inconsistency — mixing 2-space and 4-space indentation
- Tab characters used instead of spaces
- Missing colon after a mapping key
- Duplicate keys in the same mapping block
- Unclosed quotes around string values
- Invalid boolean values (use true/false, not yes/no in strict mode)
- Alias referencing an undefined anchor
- Incorrect list item indentation (dash must align with siblings)
Common Use Cases
- Validating Kubernetes manifests before running kubectl apply
- Checking Docker Compose files before docker-compose up
- Verifying CI/CD pipeline YAML (GitHub Actions, GitLab CI, CircleCI)
- Validating Helm chart values files
- Checking application configuration files before deployment
- Pre-commit hook validation to catch errors early
- Normalizing YAML formatting with the built-in formatter
Paste your YAML into the validator to get instant feedback with precise line and column error locations, making it easy to find and fix issues before they cause deployment failures.