DevToolBoxGRATIS
Blog

YAML Syntax & Validatie: Veelvoorkomende fouten en oplossingen

9 min lezenby DevToolBox

YAML (YAML Ain't Markup Language) is the go-to configuration format for Docker, Kubernetes, CI/CD pipelines, and countless other tools. Despite its human-friendly syntax, YAML is surprisingly easy to get wrong. This guide covers the most common YAML errors and how to fix them.

Where YAML Is Used

  • Docker Compose (docker-compose.yml)
  • Kubernetes manifests
  • GitHub Actions / GitLab CI workflows
  • Ansible playbooks
  • Configuration files (Prettier, ESLint, etc.)

Basic YAML Syntax Rules

Indentation

YAML uses spaces (never tabs) for indentation. The number of spaces must be consistent within the same level:

# βœ… Correct (2-space indentation)
server:
  host: localhost
  port: 8080
  database:
    name: myapp
    pool: 10

# ❌ Wrong (tab characters or inconsistent spaces)
server:
	host: localhost    # Tab character - INVALID!
   port: 8080        # 3 spaces - inconsistent!

Key-Value Pairs

Keys and values are separated by a colon followed by a space:

# βœ… Correct
name: John Doe
port: 8080

# ❌ Wrong - missing space after colon
name:John Doe

Multi-line Strings

YAML offers two block scalar styles for multi-line strings:

# | (literal block) - preserves newlines
description: |
  This is line one.
  This is line two.
  Each newline is preserved.

# > (folded block) - folds newlines to spaces
description: >
  This is a long paragraph
  that will be joined into
  a single line.

YAML Data Types

TypeSyntaxExample
Stringplain, "quoted", 'quoted'name: John
Integer42, 0xFF, 0o77port: 8080
Float3.14, .inf, .nanpi: 3.14159
Booleantrue/falsedebug: true
Nullnull, ~, (empty)value: null
DateYYYY-MM-DDdate: 2026-02-10

The "Norway Problem"

In YAML 1.1, `NO` (as in the country code for Norway) is interpreted as boolean `false`. This is because YAML 1.1 treats yes/no, on/off, true/false as booleans. Always quote country codes and similar values:

# ❌ YAML 1.1 interprets these as booleans!
country: NO        # β†’ false
answer: yes        # β†’ true
switch: on         # β†’ true

# βœ… Fix: quote the values
country: "NO"      # β†’ string "NO"
answer: "yes"      # β†’ string "yes"
switch: "on"       # β†’ string "on"

Collections: Lists and Maps

# List (sequence)
fruits:
  - apple
  - banana
  - cherry

# Nested map
database:
  host: localhost
  port: 5432
  credentials:
    user: admin
    password: secret

# Inline / Flow style
fruits: [apple, banana, cherry]
point: {x: 10, y: 20}

Top 10 Common YAML Errors

#ErrorCauseFix
1TabCharacterErrorUsing tab characters for indentationReplace all tabs with spaces (2 or 4)
2Inconsistent indentationMixing 2-space and 4-space indentationUse consistent indentation throughout the file
3Missing space after colonWriting `key:value` instead of `key: value`Always add a space after the colon
4Unquoted special charactersValues containing : or # without quotesQuote strings containing special characters
5Boolean coercionyes/no/on/off/NO interpreted as booleanQuote values that look like booleans: `"yes"`, `"NO"`
6Strings with colons`url: http://example.com` breaks at second colonQuote the entire value: `url: "http://example.com"`
7Duplicate keysSame key appears twice in a mappingRemove duplicate keys (last one wins but this is error-prone)
8Trailing whitespaceInvisible spaces after valuesConfigure editor to trim trailing whitespace
9Wrong list indentationList items not aligned with parent keyAlign `-` with child indentation level
10Missing document separatorMultiple documents without `---` separatorAdd `---` between YAML documents

YAML vs JSON vs TOML

FeatureYAMLJSONTOML
Comments# supportNone# support
Multi-line strings| and >\\n only""" triple quotes
Data typesRich (dates, etc.)Basic (6 types)Rich (dates, etc.)
ReadabilityHighMediumHigh
Machine parsingComplexSimpleMedium
Best forConfig filesAPIs, data exchangeApp config

Validation Best Practices

  • Always use a YAML linter in your CI/CD pipeline
  • Configure your editor to show whitespace characters
  • Use 2-space indentation (most common convention)
  • Quote strings that could be misinterpreted (booleans, numbers with leading zeros)
  • Use YAML schema validation for complex configurations
  • Keep YAML files small and modular when possible

FAQ

Can I use tabs in YAML?

No. YAML strictly forbids tab characters for indentation. You must use spaces. Most editors can be configured to insert spaces when you press the Tab key.

What's the difference between single and double quotes in YAML?

Single quotes preserve literal strings (no escape sequences). Double quotes allow escape sequences like \n, \t, and Unicode escapes \uXXXX. Use single quotes for simple strings and double quotes when you need escape characters.

How do I represent null in YAML?

You can use `null`, `~`, or simply leave the value empty. All three are equivalent: `key: null`, `key: ~`, and `key:` (with nothing after colon+space).

Why does YAML treat "NO" as false?

YAML 1.1 specification treats yes/no, on/off, true/false (case-insensitive) as boolean values. YAML 1.2 fixed this to only recognize true/false. To be safe, always quote strings that could be interpreted as booleans.

𝕏 Twitterin LinkedIn
Was dit nuttig?

Blijf op de hoogte

Ontvang wekelijkse dev-tips en nieuwe tools.

Geen spam. Altijd opzegbaar.

Try These Related Tools

YMLYAML Validator & FormatterY{}JSON ↔ YAML ConverterTYTOML ↔ YAML🐳Docker Compose Generator

Related Articles

JSON naar Dart: Complete Flutter Model Class Gids

Leer JSON converteren naar Dart modelklassen voor Flutter. fromJson, toJson, null safety en json_serializable.

Docker Compose YAML-validatie: 10 Veelvoorkomende Syntaxfouten en Oplossingen

Stop met tijd verspillen aan Docker Compose YAML-fouten. Leer de 10 meest voorkomende fouten te identificeren en oplossen.

JSON Schema Validatie: Typen, tools en best practices

Alles over JSON Schema-validatie: van basistypes tot geavanceerde patronen, validatiebibliotheken en integratie met TypeScript en API's.

JSON-YAML Converter Online Gids: Syntax, Tools en Best Practices

Complete gids voor JSON-YAML conversie. Syntax, js-yaml, PyYAML, yq CLI, Kubernetes, Docker Compose, YAML-valkuilen en beveiliging.