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

Also available as: JSON · Markdown
92%Fix Rate
95%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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.

generic

Workarounds

  1. 95% success Always quote string values that could be misinterpreted
    country: "NO"  # quoted to prevent boolean coercion; version: "1.0"  # prevents float coercion
  2. 88% success Use YAML safe_load and add explicit !!str tags for ambiguous values
    country: !!str NO  # explicit string tag prevents boolean interpretation
  3. 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:

  1. 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.

  2. 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.