Skip to tool
ecech.
💻 Developer & Code

In YAML, the Country Code for Norway Is false

An unquoted NO is a boolean in YAML 1.1, and so are y, n, on and off. Version 1.10 becomes 1.1. Quoting is the only portable fix.

Keys

Values protected

would change meaning unquoted

Max depth

Size change

YAML



Values that needed protecting

Advertisement

How the calculation works

A list of country codes, converted carelessly countries: - NO - SE - DK what you wrote countries: - false - "SE" - "DK" what the parser read Sweden and Denmark are fine. Norway is a boolean.

How to Use This Tool

Paste JSON and get YAML with anything ambiguous quoted. The list underneath shows every value that would have changed meaning without the quotes.

The Norway problem

YAML 1.1 resolves a set of unquoted words to booleans, and the set is much larger than true and false:

y Y yes Yes YES n N no No NO true false on On ON off Off OFF

So a list of ISO country codes containing NO parses as a list containing false. Sweden and Denmark are fine; Norway is a boolean. The same applies to y for anything abbreviated and to ON and OFF in configuration.

YAML 1.2 narrowed this to true and false only, and a great deal of tooling still implements the 1.1 behaviour — including parsers used in widely deployed systems. You cannot rely on which version will read your file, so quoting is the only portable answer.

The other three

  • Version numbers. 1.10 unquoted is the number 1.1, and the trailing zero is gone. Anything comparing versions as strings then behaves oddly.
  • Leading zeros. 022 is octal 18 in YAML 1.1. Build numbers, zero-padded identifiers and some postcodes all hit this.
  • Colons in values. 12:30 is sexagesimal 750 in YAML 1.1 — twelve sixties plus thirty. Times, ports and MAC addresses are all at risk.

All four failures share a shape: the file parses, no error is raised, and the value is a different type than intended. Nothing downstream has any reason to suspect it.

Written, then read NO false a boolean, not a country 1.10 1.1 a float, one digit short 022 18 octal, in YAML 1.1 12:30 750 sexagesimal, in YAML 1.1 Every one parses without error, which is what makes them expensive.
Quoting costs two characters and removes the entire class of problem.

Indentation rules that catch people

  • Spaces only. A tab character is a syntax error in YAML, and editors insert them silently.
  • List indentation is optional. A sequence under a key may be indented or flush with the key, and both are valid and identical. Kubernetes examples use both, which is why it looks inconsistent.
  • Indentation must be consistent within a block but not across the file, which makes mixed styles legal and unreadable.

Multi-line strings

JSON escapes newlines as \n. YAML has block scalars instead, and the two markers differ in one important way:

  • | keeps the newlines. Use it for scripts, certificates and anything where line breaks matter.
  • > folds them into spaces. Use it for prose you want to wrap in the file.

Getting these the wrong way round turns a shell script into one long line, or a paragraph into a column of fragments. This tool uses | for anything containing a newline, which is the safe default.

Advertisement

Frequently Asked Questions

What is the Norway problem in YAML?
YAML 1.1 resolves an unquoted NO to the boolean false, so a list of country codes containing Norway silently becomes a list containing false. The same applies to y, n, yes, on and off, and the file parses without any error.
Which words become booleans in YAML?
In YAML 1.1: y, Y, yes, Yes, YES, n, N, no, No, NO, true, false, on, On, ON, off, Off and OFF. YAML 1.2 narrowed it to true and false, but a lot of tooling still implements 1.1, so quoting is the only portable answer.
Why did my version number lose a digit in YAML?
Because 1.10 unquoted is the number 1.1. YAML parses it as a float and the trailing zero disappears. Quote version numbers — they are strings, not numbers, and comparing them as numbers is wrong anyway.
Why is 022 read as 18 in YAML?
Leading zeros mark an octal literal in YAML 1.1, and 022 in octal is 18. Zero-padded build numbers, identifiers and some postcodes all hit this. Quoting prevents it.
What is the difference between | and > in YAML?
The pipe keeps newlines; the greater-than folds them into spaces. Use the pipe for scripts, certificates and anything where line breaks matter, and the greater-than for prose you want wrapped in the file.
Can I use tabs to indent YAML?
No — a tab character is a syntax error. YAML requires spaces, and editors that insert tabs automatically are a common source of files that will not parse.

Related tools in Developer & Code

Browse all Developer & Code tools
The Mac mini the ecech. site is built on, beside a handwritten note reading ecech.com.

Made by one person

ecech. is not a content farm. Every tool here is written and checked by hand, one at a time, by someone who wanted the tool to exist and could not find a version that showed its working.

No accounts and no sign-in, and nothing you type reaches a server — every calculation on this page runs inside your browser. The ads are served by Google and do set their own cookies, which is set out in full on the privacy page. More about the site.