YAML Validation: The Most Common Pitfalls
YAML looks simple but bites in subtle ways. The 8 problems below account for most YAML bugs in CI/CD, Kubernetes manifests, and config files.
The Norway Problem (Boolean Coercion)
Unquoted NO is parsed as the boolean false. So country: NO becomes country: false. Same problem hits yes/no/on/off/true/false (and their case variants in YAML 1.1). Fix: quote string values that look like booleans — country: "NO".
Tabs vs Spaces
YAML forbids tabs for indentation. Most editors auto-fix this, but a stray tab from a paste will silently break parsing. Fix: configure your editor to expand tabs to 2 spaces (the standard for YAML).
Numeric Strings
version: 1.0 is parsed as the float 1.0, not the string "1.0". So version: 1.10 becomes 1.1 (trailing zero stripped). Fix: quote version numbers and other identifiers that look numeric — version: "1.10".
Multi-line Strings: | vs >
|— literal block (preserves newlines exactly)>— folded block (newlines become spaces)|+/>+— keep trailing newlines|-/>-— strip trailing newlines
Other Gotchas
- Colons in values —
url: http://example.comcan confuse parsers. Quote it. - Trailing whitespace — invisible but can break diffs and some parsers. Configure your editor to trim on save.
- Anchors and aliases (& / *) — powerful but hard to debug. Keep them simple or avoid for production config.
- Document separator —
---on its own line means a new YAML document. Easy to miss when concatenating files.
YAML to JSON (and Back)
YAML is a superset of JSON — every valid JSON document is valid YAML 1.2. Converting YAML → JSON is lossless. Converting JSON → YAML loses no data but can change formatting (comments are dropped, since JSON has none).