Skip to content

YAML Norway problem: why NO becomes false, and the other values that change (9:30, 010, dates)

One settings file tested on 1 December 2026: PyYAML changed nine values, a short Python script listed them by line, and quoting fixed all nine.

We make JSON Toolkit, the app this guide uses. The free methods come first; every step shown in JSON Toolkit was checked in the app itself, and the screenshots come from the real app with invented sample data.

Short answer

YAML 1.1, the version PyYAML follows, reads some unquoted values as something other than text: NO, no and off become false, yes and on become true, 9:30 becomes the number 570, 010 becomes 8 and 2027-04-01 becomes a date. YAML 1.2's default (core) schema reads the words, the times and the dates as text, but still reads 0150 as 150. Quoting a value makes it text in every version: country: 'NO'. To find the values to quote, run the free script below on your file; it lists each one with its line. In our test file it found nine.

Why NO becomes false: YAML 1.1 and YAML 1.2

YAML decides the type of an unquoted value by matching it against a list of patterns; a value that matches none of them is text. That list changed between versions of the specification.

In YAML 1.1 (2005), the boolean type includes yes, no, on and off, each in three spellings, and the single letters y and n, next to true and false. Its integer type reads a leading 0 as octal, so 010 is 8, and numbers separated by a colon as base 60, which it calls convenient for times and angles, so 9:30 is 9 times 60 plus 30. Dates go through a third YAML 1.1 type, timestamp: PyYAML reads 2027-04-01 as a date, as its output below shows.

YAML 1.2, published in 2009, set out to make YAML a strict superset of JSON and, in the words of the current specification, removed many of the problematic implicit typing recommendations. Its core schema, the recommended default, reads only true and false (in three spellings) as booleans, null and ~ as null, decimal numbers, 0o for octal and 0x for hexadecimal; anything else unquoted is text, and anything quoted is text.

Not every tool moved to 1.2. PyYAML, the Python library you import as yaml, describes itself as a complete YAML 1.1 parser. Which rules your own tool follows depends on its library; the commands below show what yours does.

What PyYAML did to one settings file

Our test file holds the booking settings of an invented Norwegian bike hire shop, typed by hand the way such files usually are:

# Fjord Cycle Hire booking settings (an invented shop)
shop: Fjord Cycle Hire
country: NO
ships_to: [NO, SE, DK, FI]
currency: NOK
opens: 9:30
closes: 17:45
season_starts: 2027-04-01
postcode: 0150
settings_version: 010
newsletter: on
deposit_required: yes

We loaded it with PyYAML 6.0.3 (Python 3.11.9, Windows 11) on 1 December 2026, in the folder that holds the file:

py -3 -I -c "import yaml; print(yaml.safe_load(open('booking-settings.yaml', encoding='utf-8')))"
{'shop': 'Fjord Cycle Hire', 'country': False, 'ships_to': [False, 'SE', 'DK', 'FI'], 'currency': 'NOK', 'opens': 570, 'closes': 1065, 'season_starts': datetime.date(2027, 4, 1), 'postcode': 104, 'settings_version': 8, 'newsletter': True, 'deposit_required': True}

Nine values changed. The country and the first country in the list became False. The opening times became 570 and 1065, minutes after midnight read in base 60. The season start became a date object. The postcode 0150 became 104 and the settings version 010 became 8, both read as octal. The two switches became True. Only shop, currency and the other three countries stayed as typed.

Most of these pass without an error: a program simply gets the wrong value. The date is the exception when you convert to JSON, because JSON has no date type:

py -3 -I -c "import json, yaml; print(json.dumps(yaml.safe_load(open('booking-settings.yaml', encoding='utf-8'))))"
TypeError: Object of type date is not JSON serializable

Method 1 (free): list the values with a script

This Python script reads every unquoted value of a YAML file, keys included, once with PyYAML's YAML 1.1 rules and once with the YAML 1.2 core schema's patterns from the specification, and prints each value the two read differently, with its line. It needs Python and PyYAML (py -m pip install pyyaml). The -I in the commands runs Python in isolated mode, so it does not import files from the current folder; it also skips packages installed with pip --user, so if Python says No module named 'yaml', run the command without -I.

"""List the plain (unquoted) values of a YAML file that a YAML 1.1 reader such as PyYAML reads differently from a
YAML 1.2 reader, with their line. Quote each one listed, and every reader gets the same text.
Usage: py yaml_traps.py <file.yaml>"""
import re
import sys

import yaml

CORE_1_2 = [("null", r"~|null|Null|NULL|"),                                    # the YAML 1.2 core schema
            ("bool", r"true|True|TRUE|false|False|FALSE"),
            ("int", r"[-+]?[0-9]+|0o[0-7]+|0x[0-9a-fA-F]+"),
            ("float", r"[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?|[-+]?\.(inf|Inf|INF)|\.(nan|NaN|NAN)")]
resolver = yaml.resolver.Resolver()                                            # PyYAML's YAML 1.1 rules


def read_1_2(text):
    for kind, pattern in CORE_1_2:
        if re.fullmatch(pattern, text):
            if kind == "int":
                return kind, int(text, 0) if text[:2] in ("0o", "0x") else int(text)
            if kind == "float":                                         # .inf and .nan: float() wants inf and nan
                return kind, float(text.lower().replace(".inf", "inf").replace(".nan", "nan"))
            return kind, yaml.safe_load(text)
    return "str", text


def read_1_1(text):
    kind = resolver.resolve(yaml.ScalarNode, text, (True, False)).rsplit(":", 1)[-1]
    return ("str", text) if kind in ("str", "merge", "value") else (kind, yaml.safe_load(text))


with open(sys.argv[1], encoding="utf-8") as f:
    events = list(yaml.parse(f))
found = 0
for event in events:
    if isinstance(event, yaml.ScalarEvent) and event.style is None:    # plain: no quotes, no | or > block
        text = event.value
        new, old = read_1_2(text), read_1_1(text)
        if (new[0], repr(new[1])) != (old[0], repr(old[1])):
            found += 1
            print(f"line {event.start_mark.line + 1}: {text}  YAML 1.2: {new[0]} {new[1]!r}  "
                  f"YAML 1.1 (PyYAML): {old[0]} {old[1]!r}")
print(f"{found} value(s) read differently")

On the test file:

py -3 -I yaml_traps.py booking-settings.yaml
line 3: NO  YAML 1.2: str 'NO'  YAML 1.1 (PyYAML): bool False
line 4: NO  YAML 1.2: str 'NO'  YAML 1.1 (PyYAML): bool False
line 6: 9:30  YAML 1.2: str '9:30'  YAML 1.1 (PyYAML): int 570
line 7: 17:45  YAML 1.2: str '17:45'  YAML 1.1 (PyYAML): int 1065
line 8: 2027-04-01  YAML 1.2: str '2027-04-01'  YAML 1.1 (PyYAML): timestamp datetime.date(2027, 4, 1)
line 9: 0150  YAML 1.2: int 150  YAML 1.1 (PyYAML): int 104
line 10: 010  YAML 1.2: int 10  YAML 1.1 (PyYAML): int 8
line 11: on  YAML 1.2: str 'on'  YAML 1.1 (PyYAML): bool True
line 12: yes  YAML 1.2: str 'yes'  YAML 1.1 (PyYAML): bool True
9 value(s) read differently

Lines 9 and 10 show why the versions are not the whole story: YAML 1.2 reads 0150 and 010 as the numbers 150 and 10. If a value is a code, such as a postcode, an account number or a version, quoting is the only way to keep it exactly as typed.

Method 2 (free): quote them, and check

Put single or double quotes around each value the script lists. A quoted value is text in YAML 1.1 and in YAML 1.2. The quoted copy of the test file:

# Fjord Cycle Hire booking settings (an invented shop)
shop: Fjord Cycle Hire
country: 'NO'
ships_to: ['NO', SE, DK, FI]
currency: NOK
opens: '9:30'
closes: '17:45'
season_starts: '2027-04-01'
postcode: '0150'
settings_version: '010'
newsletter: 'on'
deposit_required: 'yes'

The script now lists nothing, and PyYAML reads every value as text, leading zeros included:

py -3 -I yaml_traps.py "booking-settings (quoted).yaml"
0 value(s) read differently
py -3 -I -c "import json, yaml; print(json.dumps(yaml.safe_load(open('booking-settings (quoted).yaml', encoding='utf-8'))))"
{"shop": "Fjord Cycle Hire", "country": "NO", "ships_to": ["NO", "SE", "DK", "FI"], "currency": "NOK", "opens": "9:30", "closes": "17:45", "season_starts": "2027-04-01", "postcode": "0150", "settings_version": "010", "newsletter": "on", "deposit_required": "yes"}

Going the other way, from JSON to YAML, PyYAML's safe_dump quotes the text that PyYAML itself would read as something else (here all nine values), and leaves the rest plain (SE, DK and FI mean nothing else):

py -3 -I -c "import json, yaml; print(yaml.safe_dump(json.load(open('booking-settings-export.json', encoding='utf-8')), sort_keys=False))"
shop: Fjord Cycle Hire
country: 'NO'
ships_to:
- 'NO'
- SE
- DK
- FI
currency: NOK
opens: '9:30'
closes: '17:45'
season_starts: '2027-04-01'
postcode: '0150'
settings_version: '010'
newsletter: 'on'
deposit_required: 'yes'

It does not quote text that only YAML 1.2 reads as a number: we checked, and safe_dump wrote 1e3 and 0o17 without quotes, which a YAML 1.2 reader takes as 1000.0 and 15. So these values usually go wrong in YAML that people type or edit by hand, but run the script on files a library wrote too. Another way out is a reader that treats every value as text by default; the StrictYAML documentation describes that approach, starting from the same Norway example. We did not test it.

Method 3: find them and convert with JSON Toolkit

JSON Toolkit is our Windows app for checking, formatting, comparing and converting JSON, YAML and CSV files, up to 100 MB each, offline. The screenshots below come from version 1.0.0 (evaluation build), with the same two invented files: the hand-typed YAML and the shop's export of the same settings as JSON, where every value is text.

  1. Add the folder. The app checks every file in it: the YAML file got 9 warnings, the JSON export OK.
  2. Read the problems. The table lists the same nine values as the script, each with its line, column and path. For the country on line 3, column 10, it says: NO: read here (YAML 1.2) as text, but YAML 1.1 tools (PyYAML and other older libraries) read false; quote it to be sure.
  3. Preview the JSON copy. The app reads by the YAML 1.2 rules: NO, the times, the date, on and yes stay text, and a note above the preview says that 9 values were read by those rules. The postcode and the settings version come out as 150 and 10, as YAML 1.2 reads them. To keep 0150 and 010, quote them in the YAML first.
  4. Convert the export to YAML. The preview of the JSON export as YAML says nothing in the data changes, and it quotes the nine values.
JSON Toolkit with booking-settings.yaml marked 9 warnings and the JSON export OK; the problems table lists country, ships_to, opens, closes, season_starts and postcode with line and column, and the message for NO on line 3 is shown above the file with the nine lines highlighted.
Nine values that YAML 1.1 tools read differently, each with its line and column. JSON Toolkit 1.0.0 (evaluation build), tested 1 December 2026, invented sample files.
The JSON copy preview of booking-settings.yaml: country NO, the times and the date kept as text, postcode 150 and settings_version 10 as numbers, with the note that 9 values were read by the YAML 1.2 rules.
The JSON copy keeps NO and the times as text, but writes 0150 and 010 as 150 and 10. JSON Toolkit 1.0.0 (evaluation build), tested 1 December 2026, invented sample files.
The YAML copy preview of booking-settings-export.json, with NO, 9:30, 17:45, 2027-04-01, 0150, 010, on and yes in quotes and the note that nothing in the data changes.
The YAML copy of the JSON export, with the values quoted. JSON Toolkit 1.0.0 (evaluation build), tested 1 December 2026, invented sample files.

We saved both copies and read them back with Python. The JSON copy has 150 and 10 as numbers and every other value as text. The YAML copy, read with PyYAML, gives exactly the data of the JSON export, and it is byte for byte the YAML that PyYAML's own safe_dump writes. The app leaves the original files as they are; copies are new files. To check that a converted file still says the same thing as its original, see Compare two JSON files by meaning.

How to Format, Validate and Compare JSON Offline on Windows1:04Watch on YouTubeNothing loads from YouTube until you press play. The player then loads from youtube-nocookie.com, YouTube's privacy-enhanced mode, and connects to Google's servers. Privacy

Limitations

  • The script compares PyYAML's rules with YAML 1.2. The YAML 1.1 list also makes y and n booleans, but PyYAML reads y as text (we checked), so the script does not list single letters. Other YAML 1.1 readers may read them as booleans: quote them if your file has them.
  • A value that both versions read as the same number is not listed: a release number such as 1.10 is read as 1.1 by both (we checked). Quote version numbers, codes and anything with leading zeros, whatever the script says.
  • We tested PyYAML 6.0.3 only. Libraries in other languages, and other Python libraries, follow their own rules; run the load command, or its equivalent, with the library your tool uses.
  • JSON Toolkit's copies follow YAML 1.2, so unquoted leading zeros are not kept. Its planned requirements: Windows 10 (22H2) or 11, 64-bit.
  • The files are invented, and the results come from one test day, 1 December 2026.

References