data
parsing
ai_generated
true
YAML file silently converts country code 'NO' to boolean False, or version '1.0' to float
ID: data/yaml-norway-problem-boolean-coercion
92%Fix Rate
95%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| any | active | — | — | — |
Root Cause
YAML 1.1 aggressively coerces unquoted values: NO/no/off -> False, YES/yes/on -> True, 1.0 -> float, 1_000 -> integer. The 'Norway problem': country code NO becomes boolean False. YAML 1.2 fixed this but most tools use 1.1.
genericWorkarounds
-
95% success Always quote string values that could be misinterpreted
country: "NO" # quoted to prevent boolean coercion; version: "1.0" # prevents float coercion
-
88% success Use YAML safe_load and add explicit !!str tags for ambiguous values
country: !!str NO # explicit string tag prevents boolean interpretation
-
82% success Use JSON for data interchange where type ambiguity is unacceptable
JSON has no implicit type coercion. Strings are always quoted. Consider JSON for config shared across tools.
Dead Ends
Common approaches that don't work:
-
Write YAML values without quotes and trust they stay as strings
95% fail
YAML 1.1 interprets: NO->false, YES->true, null->None, 1.0->float, 0o10->8(octal). Country codes, version numbers, and on/off flags are all affected.
-
Upgrade to YAML 1.2 parser to fix the problem
82% fail
Most tools (Ansible, Kubernetes, Docker Compose, GitHub Actions) still use YAML 1.1 parsers. Your files must be compatible with consumers.