The Norway problem: why YAML turns NO, yes and off into booleans

YAML 1.1 treats y, yes, on, true, n, no, off and false in any common capitalisation as booleans. YAML 1.2 narrowed that to true and false, but PyYAML, Ruby’s Psych, Go’s yaml.v2 and many tools built on them still follow 1.1. So the list GB, SE, NO loads as "GB", "SE", false. This is not a syntax error, so PasteKit formats the sample and adds an info note on each affected value; quoting the value makes it unambiguous in every parser.

Seen as:

  • 'NO' is the string "NO" in YAML 1.2 but the boolean false in YAML 1.1
  • json: cannot unmarshal bool into Go struct field EnvVar.spec.template.spec.containers.env.value of type string
  • {'countries': ['GB', 'SE', False]}

Input

Settings

History

Load from URL

Common causes

1. Country and language codes

NO (Norway) is the famous case, but ON (Ontario) and Y/N flags hit the same rule. Quote codes and short flags.

Before
countries:
  - GB
  - SE
  - NO
After
countries:
  - GB
  - SE
  - "NO"

2. yes/no and on/off answers meant as text

A setting such as mode: off reaches a 1.1 parser as false, which the application may treat very differently from the string “off”. Quote it, or use a real boolean if a boolean is what the program expects.

Before
debug: off
answer: yes
After
debug: "off"
answer: "yes"

3. Kubernetes environment variable values

Container env values must be strings. value: yes or value: true is parsed as a boolean and kubectl rejects the manifest with “cannot unmarshal bool into Go struct field”.

Before
env:
  - name: FEATURE_X
    value: yes
After
env:
  - name: FEATURE_X
    value: "yes"

4. The GitHub Actions on: key

GitHub reads workflows correctly, but if you load a workflow with PyYAML the top-level on: key becomes the boolean True. Quote it when processing workflows with YAML 1.1 tools.

Before
on:
  push:
    branches: [main]
After
"on":
  push:
    branches: [main]

5. Numbers that are not what they seem

The same implicit typing turns version: 1.10 into the float 1.1, mode: 0755 into an octal number in 1.1, and 22:30 into 1350 (base-60) in 1.1. Quote anything that is an identifier rather than a quantity.

Before
version: 1.10
mode: 0755
start: 22:30
After
version: "1.10"
mode: "0755"
start: "22:30"

Frequently asked questions

Which parsers still use YAML 1.1 rules?

PyYAML, Ruby Psych, Go’s gopkg.in/yaml.v2 and SnakeYAML 1.x apply 1.1 booleans. ruamel.yaml, the JavaScript yaml package and Go’s yaml.v3 default to 1.2, where only true and false are booleans.

Does quoting change the value for 1.2 parsers?

No. In YAML 1.2, NO and “NO” are both the string NO, so quoting is harmless there and protective everywhere else.

Can PasteKit parse as YAML 1.1?

Yes. Switch the YAML version option to 1.1 and the Tree view and conversions show the values as a 1.1 parser would, with a warning on each implicit boolean.

Related