YAML auto-types your scalars; you can override
A bare value like port: 8000 reads as an integer. port: "8000" reads as a string. The parser guesses the type from the bare form. This convenience is also YAML's most famous footgun.
The five scalar styles
- Bare (plain) —
name: Pippa. Parser guesses type. - Single-quoted —
name: 'Pippa'. Always a string. Backslashes are literal. - Double-quoted —
name: "Pippa". Always a string. Supports JSON-style escapes (\n,\t,\u00e9). - Literal block (
|) — multi-line, preserves newlines. - Folded block (
>) — multi-line, joins lines into one with spaces.
Booleans, the Norway problem
YAML 1.1 (still the default in many parsers, including Kubernetes pre-1.22) treats 22 unquoted strings as booleans: y, Y, yes, Yes, YES, n, N, no, No, NO, true, True, TRUE, false, False, FALSE, on, On, ON, off, Off, OFF. So country: NO reads as country: False. The fix: always quote string values that look like keywords. country: "NO" is a string.
Null
Four bare forms all parse as null: null, Null, NULL, ~. An empty value (key with nothing after the colon) is also null. To say the literal string 'null', quote it: 'null'.
countries: [GB, IE, NO, DE]. The YAML 1.1 parser turned NO into False. Norway disappeared from the list, the booking system silently stopped sending mail to Norwegian addresses, and the bug took weeks to find. Quote anything that could be misread as a keyword.