YAML Viewer, Formatter & Validator · Tutorial

How to fix the YAML Norway problem and similar bugs

6 min readbeginnerUpdated

Your YAML file is valid, yet a Python script reads Norway as false and a file mode as 493. This tutorial shows how to use the Validate tab of the YAML Viewer, Formatter & Validator to find every value that YAML 1.1 parsers read differently from YAML 1.2, understand each warning and fix the file so it behaves the same everywhere.

What you need

Steps

  1. Paste the YAML

    Paste the file into the left box or open it with the file picker. The sample is a shop's shipping settings with a list of country codes, a few switches, a file mode and a cut-off time.

  2. Read the summary

    The message under the problem list says Valid YAML (1 document, 6 keys), with 4 portability warnings. Valid means no parser will reject the file. The warnings are about values that different parsers will read in different ways.

  3. Fix the country code

    The first warning points at line 5, column 5: "NO" is text in YAML 1.2 but true/false in YAML 1.1 parsers. PyYAML and other YAML 1.1 libraries turn the Norway code into false. Put it in quotes so it stays a string.

    - NO      ← false in YAML 1.1
    - "NO"    ← always the text NO
  4. Decide what on, 0755 and 17:30 should be

    free_shipping: on is meant as a switch, so write true to make it a real boolean everywhere. 0755 is a directory mode: older parsers read it as octal 493, newer ones as 755. Quote it if the program expects text. 17:30 is read by YAML 1.1 as the base-60 number 1050, so quote it as "17:30" to keep it as a time.

  5. Check the empty value

    The last line of the report is a Note for gift_wrap, which has no value and therefore means null. If that was deliberate, leave it. Otherwise add a value, or "" for empty text.

  6. Confirm the file is clean

    After your edits the summary turns green and reads Valid YAML: 1 document, 6 keys. If you gave gift_wrap a value, the right box says No problems found; if you kept it empty on purpose, only that note remains. Copy the corrected file back into your project.

Try it yourself

Opens the YAML Viewer, Formatter & Validator with this tutorial's sample loaded.

Try it now

Common mistakes

Quoting every value
Only the values the validator flags need attention. Quoting numbers that should be numbers, like port: 8080, turns them into strings and can break the program that reads them.
Writing yes and no for booleans
Use true and false. They mean the same thing in every YAML version, while yes and no do not.
Assuming your parser is YAML 1.2
Many widely used libraries still follow YAML 1.1. If a file is shared between tools, write it so both versions agree.

Next steps

Go back to the YAML Viewer, Formatter & Validator, or keep going with one of these:

FAQ

Why is it called the Norway problem?

Because the ISO country code for Norway, NO, is the best-known value that YAML 1.1 parsers silently turn into false.

Do I need to fix warnings if the file works?

Not always. They matter when another tool, a newer library or a colleague's script reads the same file.