YAML gotchas: why NO becomes false and 0755 becomes 493
By Hammad Rasool · November 11, 2026
Quick answer: unquoted YAML values are guessed. Depending on the parser, NO can become false, 0755 can become 493, 12:30 can become 750, and 3.10 becomes 3.1 everywhere. The guessing rules changed between YAML 1.1 and YAML 1.2, and popular parsers still follow different versions. The fix is the same for all of them: quote any value that must stay a string. JSON doesn't have this problem because strings are always quoted.
How this was tested: on 11 November 2026 the same 22 YAML snippets were loaded with three parsers: js-yaml 5.4.2 in Node.js (the library behind ToolStash's YAML to JSON converter), PyYAML 6.0.3 with safe_load, and ruamel.yaml 0.19.1 in safe mode. Every value in the tables is copied from those runs. Go, Ruby and Java parsers were not tested.
The same YAML, three different results
| YAML | js-yaml 5.4.2 | PyYAML 6.0.3 | ruamel.yaml 0.19.1 |
|---|---|---|---|
country: NO | "NO" | false | "NO" |
answer: yes | "yes" | true | "yes" |
enabled: on | "on" | true | "on" |
on: push (as a key) | key "on" | key true | key "on" |
mode: 0755 | 755 | 493 (octal) | 755 |
zip: 01234 | 1234 | 668 (octal) | 1234 |
mode: 0o755 | 493 | "0o755" | 493 |
time: 12:30 | "12:30" | 750 (base 60) | "12:30" |
python: 3.10 | 3.1 | 3.1 | 3.1 |
n: 1_000 | "1_000" | 1000 | 1000 |
a: 1e3 | 1000 | "1e3" | 1000.0 |
phone: +923001234567 | 923001234567 | 923001234567 | 923001234567 |
color: #fff | null | null | null |
d: 2026-11-11 | "2026-11-11" | date object | date object |
a: .inf | Infinity | inf | inf |
a: 1 then a: 2 | error | 2 (last wins) | error |
js-yaml and ruamel.yaml follow YAML 1.2, where only true, false and null (in a few capitalisations) are special words. PyYAML follows YAML 1.1, where yes, no, on and off are booleans, a leading zero means octal, and 12:30 is a base-60 number. A file that works in a Node.js tool can therefore change meaning when a Python script reads it.
The Norway problem
countries:
- GB
- NO
- SEPyYAML loaded the country code NO as false; js-yaml and ruamel.yaml kept it as "NO". Any two-letter value that happens to be NO, ON, YES or similar is at risk, and so is a config option set to off that your code expects as a string.
The same rule affects keys. GitHub Actions workflows start with on: push; PyYAML read that key as the boolean true, so a Python script looking for data["on"] won't find it. js-yaml and ruamel.yaml kept the key as "on".
Numbers that lose information
- Leading zeros. A zip or account code such as
01234became1234in the YAML 1.2 parsers and668in PyYAML, which read it as octal. File modes are the opposite trap:0755is octal for493, but the YAML 1.2 parsers read it as decimal755. Write0o755for an octal number in YAML 1.2, or quote it. - Version numbers.
3.10became3.1in all three parsers. This is a common way for a CI job to ask for Python 3.1 instead of 3.10. - Phone numbers.
+923001234567became the number923001234567everywhere: the plus sign is gone, and a number with a leading zero would lose that too. - Times. PyYAML read
12:30as750(12 × 60 + 30) and22:22, as in a port mapping, as1342. Quote times and port mappings. - Underscores and exponents differ too:
1_000stayed a string in js-yaml but was 1000 in the other two, and1e3was a string in PyYAML but a number elsewhere.
# starts a comment, even in a value
color: #fff loaded as null in all three parsers: a # after a space starts a comment, so the value is empty. bg: '#fff' kept the colour.
Errors you will see
| YAML | js-yaml message | PyYAML message |
|---|---|---|
title: Step 1: install | bad indentation of a mapping entry (1:14) | mapping values are not allowed here |
| A tab used for indentation | tab characters must not be used in indentation (2:1) | while scanning for the next token |
| The same key twice | duplicated mapping key (2:1) | no error: the last value wins |
A second colon followed by a space needs quotes: title: "Step 1: install". YAML indentation must use spaces. And because PyYAML keeps the last duplicate silently, a config file can carry a stale value that one tool ignores and another rejects.
The fix: quote what must stay a string
country: "NO"
enabled: "on"
mode: "0755"
zip: "01234"
python: "3.10"
time: "12:30"
phone: "+923001234567"
color: "#fff"Double or single quotes both work. Libraries already do this when they write YAML: js-yaml's dump quoted every risky value in the test, including the key on, even though js-yaml itself would read them as strings:
country: 'NO'
answer: 'yes'
'on': push
mode: '0755'
version: '3.10'
color: '#fff'
t: '12:30'
phone: '+923001234567'PyYAML's safe_dump quoted NO, yes, 0755, 3.10 and 12:30 the same way. The JSON to YAML converter uses js-yaml, so its output is safe to hand to a YAML 1.1 parser. Problems come from YAML typed by hand.
Merge keys and anchors
base: &base
retries: 3
timeout: 30
prod:
<<: *base
timeout: 60&base names a block and <<: *base copies its keys, a pattern common in docker-compose and CI files. PyYAML and ruamel.yaml produced prod: {retries: 3, timeout: 60}. js-yaml 5.4.2 with its default settings did not: it kept a literal key named "<<", because merge keys are a YAML 1.1 feature that its default schema leaves out. ToolStash's YAML to JSON converter now turns merge keys on, so it gives the same result as the Python parsers. If you use js-yaml in your own code, load with { schema: CORE_SCHEMA.withTags(mergeTag) }.
What gets lost going from YAML to JSON
- Comments disappear: JSON has none.
- .inf and .nan are valid YAML numbers, but JSON has no such values. In the test,
JSON.stringifyturned them intonullwithout an error. - Dates became date objects in both Python parsers and stayed strings in js-yaml. In JSON they end up as strings either way.
- Anchors are expanded, so repeated blocks are written out in full.
Going the other way is safe: YAML 1.2 was designed so that JSON documents are valid YAML. If you control the format and don't need comments, JSON avoids every problem on this page; YAML is worth it for files people edit by hand.
Checklist for hand-written YAML
- Quote country codes,
yes/no/on/offvalues, version numbers, times, zip codes, phone numbers and colours. - Find out which YAML version the tool reading the file follows: PyYAML is YAML 1.1.
- Indent with spaces, never tabs.
- Quote any value with a colon followed by a space, or a # preceded by a space.
- Paste the file into the YAML to JSON converter and read the result: a number where you expected text shows up immediately.
FAQ
Why does YAML turn NO into false?
In YAML 1.1, no in any of its common capitalisations is a boolean. YAML 1.2 dropped that, but PyYAML and other parsers still follow 1.1. Quote it: "NO".
Is JSON valid YAML?
Yes for YAML 1.2, which made JSON a subset. You can paste JSON where YAML is expected; it loaded unchanged in the test.
Should I use single or double quotes in YAML?
Either. Double quotes allow escapes such as \n; inside single quotes a backslash is just a backslash and a quote is written ''.
How do I keep a version like 3.10 as text?
Quote it: python: "3.10". Unquoted, every parser tested returned 3.1.
Is my YAML uploaded when I convert it?
No. The converters run in your browser.