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
- The YAML Viewer, Formatter & Validator (Validate tab)
- A YAML file that behaves oddly in one program, or the sample from the Try it button
Steps
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.
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.
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 intofalse. Put it in quotes so it stays a string.- NO ← false in YAML 1.1 - "NO" ← always the text NODecide what on, 0755 and 17:30 should be
free_shipping: onis meant as a switch, so writetrueto make it a real boolean everywhere.0755is a directory mode: older parsers read it as octal 493, newer ones as 755. Quote it if the program expects text.17:30is read by YAML 1.1 as the base-60 number 1050, so quote it as"17:30"to keep it as a time.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.Confirm the file is clean
After your edits the summary turns green and reads Valid YAML: 1 document, 6 keys. If you gave
gift_wrapa 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.
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
trueandfalse. They mean the same thing in every YAML version, whileyesandnodo 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.