Skip to content
Common YAML Pitfalls
step 1/5

Reading — step 1 of 5

Read

~1 min readProduction

Common YAML Pitfalls

YAML's flexibility is also its danger.

The Norway Problem (YAML 1.1):

country_codes:
  - NO   # Norway → boolean false!
  - SE   # Sweden → string "SE"

Result: [false, "SE"].

Fix: quote: - "NO". Or use YAML 1.2 (only true/false are bool).

Octal interpretation:

zip: 01234     # YAML 1.1: octal (= 668). YAML 1.2: integer 1234.

Quote: zip: "01234".

Floats vs strings:

version: 1.0    # float 1.0 (loses trailing 0)
version: 1.10   # parsed as 1.1!
version: "1.10" # string "1.10"

Quote version strings.

Sexagesimal (ancient YAML 1.1):

time: 12:30    # 12*60 + 30 = 750 (sexagesimal int!)

YAML 1.2 fixed this. Old parsers may still treat as int.

Indentation tabs:

key:
	value   # tab → parser error

Use spaces. Configure editor to display tabs.

Trailing colon:

key:value      # parsed as one string "key:value", not a map!
key: value     # correct

Need space after colon.

Empty document:

---

Parsed as null, not empty document.

!!str on int:

zip: !!str 01234     # forces string "1234" (lost leading zero)
zip: "01234"          # safe

Even !!str runs through int parsing first.

Anchors with merge keys edge cases:

  • Order matters in some parsers.
  • << is technically an extension; not all parsers support.

Whitespace in values:

greeting: hello world    # trailing whitespace stripped
greeting:    hello world # leading also stripped

Quote to preserve whitespace.

Comments-in-values:

key: value # comment    → parsed as "value"
key: 'value # not a comment'     preserved

Be aware of quote rules.

Linters:

  • yamllint: catches indent issues, line length, key duplication.
  • cfn-lint: AWS CloudFormation specifics.
  • kubeval: K8s schema validation.

Run them in CI.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…