Developers · 30 November 2026 · 3 min read

YAML Gotchas: The Norway Problem, Tabs and Other Traps

By

The YAML mistakes that break configs: tabs, unquoted yes and no, versions that turn into numbers, port mappings read as times, multiline strings and anchors.

YAML Gotchas: The Norway Problem, Tabs and Other Traps

YAML is the language of modern configuration: Kubernetes, Docker Compose, Ansible, GitHub Actions and countless apps. It is pleasant to read, and that is part of the danger. A file can look perfectly right and still mean something different to the parser. The fastest way to see what the parser really understood is to convert the file to JSON with the YAML to JSON converter. Here are the traps that come up again and again.

1. Indentation and tabs

YAML uses indentation to show structure, and tabs are not allowed for it. Many editors insert a tab when you press the key, and the error message that follows is rarely helpful. Configure your editor to insert spaces in YAML files (two is the common choice).

The subtler problem is indentation that is valid but wrong. Compare:

env:
  - name: MODE
    value: prod

env:
  - name: MODE
  value: prod

In the first, value belongs to the list item. In the second, it is a sibling of env at the top level, and your container never gets it. No error, just a missing setting.

2. The Norway problem

In YAML 1.1, unquoted words such as yes, no, on and off are booleans. So a list of country codes like this:

countries:
  - DE
  - FR
  - NO

gives you "DE", "FR" and false. YAML 1.2 fixed this: only true and false are booleans. The catch is that many widely used libraries, including PyYAML in Python, still follow 1.1 rules. Your file can work in one tool and break in another. The safe habit: quote any string that could look like something else, as in "NO" or "off".

3. Strings that look like numbers, dates or times

  • version: 1.10 is the number 1.1. Write "1.10".
  • zip: 01234 may be read as an octal number by YAML 1.1 parsers, or lose its leading zero. Quote postcodes, phone numbers and IDs.
  • - 22:22 in a Docker Compose port list can be read by YAML 1.1 parsers as a base-60 number (1342). That is why port mappings are usually written as "22:22".
  • date: 2026-11-30 may become a date object rather than a string, depending on the library.
  • ~, null or an empty value after the colon all mean null, not an empty string.

Strings that start with special characters such as *, &, !, @, % or a backtick also need quotes, and so do values containing : (colon and space) or # (space and hash), because the parser reads those as a new key or the start of a comment. A password like p@ss #1 is silently cut to p@ss if it is not quoted.

4. Multiline strings

YAML has two block styles, and choosing the wrong one changes your text:

IndicatorNewlinesGood for
| literalKept as writtenScripts, certificates, config snippets
> foldedSingle newlines become spacesLong descriptions

Both add one final newline by default. Add - to remove it (|-) or + to keep all trailing newlines (|+). An unexpected trailing newline in a token or a password is a classic “it works when I type it, not from the config” bug. For shell scripts in CI files, always use |, or the lines are joined into one long command.

5. Anchors, aliases and duplicate keys

Anchors (&defaults) and aliases (*defaults) let you reuse a block, and the merge key <<: *defaults copies its keys into another map. They are handy, but the merge key comes from YAML 1.1 and not every tool supports it. When converted to JSON, aliases are expanded, which is a good way to check that the merge produced what you meant.

Duplicate keys are another quiet trap. The spec forbids them, but many parsers simply keep the last value. If you define image: twice in a long file, the first one is ignored without warning.

Our take

When a YAML config behaves strangely, stop reading it as YAML. Convert it to JSON, where types, nesting and quotes are explicit, and the mistake usually jumps out within seconds. Going the other way, the JSON to YAML converter quotes values that would otherwise change type, which makes it a safe way to produce a starting file. Beyond that: spaces only, quote anything that is not obviously a plain word or number, and add a linter such as yamllint to your editor or CI. It catches tabs, duplicate keys and indentation slips before they reach production.

Anthony ParkerNetwork and systems engineer

Anthony has worked in IT for more than 17 years: office and field networks, servers, telephony, user support and security patching in international organisations. He writes about networking, security, developer tools and calculators.