YAML field notes · 04
YAML vs JSON: the type surprises (Norway, 0755, 1.10) that break conversions
JSON writes every type one way: strings always have quotes. YAML guesses the type of unquoted text, and the guess depends on the YAML version. Of the 26 unquoted values we tested, 15 give different data in a YAML 1.2 parser and in a YAML 1.1 parser such as PyYAML. The fix is the same for all of them: quote values that must stay text.
The short comparison
| JSON | YAML | |
|---|---|---|
| Strings | Always in double quotes | Quotes optional; unquoted text may become a boolean, number, date or null |
| Comments | None (RFC 8259) | # to end of line (how they work) |
| Reuse | None | Anchors, aliases, << merge keys (guide) |
| Several documents per file | No | Yes, split by --- |
| Long text | One line with \n | | and > blocks (guide) |
| Infinity, NaN | “not permitted” (RFC 8259, section 6) | .inf, .nan |
The YAML 1.2.2 specification says the main goal of version 1.2 was “making YAML a strict superset of JSON” (history), so almost any JSON file is already valid YAML 1.2. The exception is a key written twice: RFC 8259 only says names “SHOULD be unique”, while YAML forbids duplicates. Going from YAML to JSON is where data changes, and the type of an unquoted value is the change that is easiest to miss.
26 unquoted values, three parsers
We put all of them in one file and read it three ways: the converter’s default YAML 1.2 reading, its YAML 1.1 reading, and PyYAML 6.0.3’s safe_load. The first 15 rows are the ones where YAML 1.2 and 1.1 disagree.

Open this example in the converter →
| YAML | YAML 1.2 → JSON | YAML 1.1 → JSON | PyYAML 6.0.3 |
|---|---|---|---|
country: NO | "NO" | false | False |
answer: no | "no" | false | False |
enabled: yes | "yes" | true | True |
switch: on | "on" | true | True |
off_value: off | "off" | false | False |
octal_old: 0755 | 755 | 493 | 493 |
octal_new: 0o755 | 493 | "0o755" | '0o755' |
leading_8: 0800 | 800 | "0800" | '0800' |
binary: 0b101 | "0b101" | 5 | 5 |
underscore: 1_000 | "1_000" | 1000 | 1000 |
exp: 1e3 | 1e3 | "1e3" | '1e3' |
ports: 22:22 | "22:22" | 1342 | 1342 |
time: 1:30 | "1:30" | 90 | 90 |
date: 2026-11-08 | "2026-11-08" | "2026-11-08T00:00:00.000Z" | date(2026, 11, 8) |
stamp: 2026-11-08T10:00:00Z | "2026-11-08T10:00:00Z" | "2026-11-08T10:00:00.000Z" | datetime(2026, 11, 8, 10, 0, tzinfo=utc) |
flag_y: y | "y" | "y" | 'y' |
title_true: True | true | true | True |
tilde: ~ | null | null | None |
empty: | null | null | None |
hex: 0x1F | 31 | 31 | 31 |
version: 1.10 | 1.10 | 1.10 | 1.1 |
exp_signed: 1.0e+3 | 1.0e+3 | 1.0e+3 | 1000.0 |
inf: .inf | null | null | inf |
nan: .NaN | null | null | nan |
big: 12345678901234567890 | 12345678901234567890 | 12345678901234567890 | 12345678901234567890 |
plus: +5 | 5 | 5 | 5 |
The YAML 1.1 column gives the same value as PyYAML on every row except where JSON has nothing equivalent: the two timestamps and .inf/.NaN (see below). Read as YAML 1.1 in the converter with Read as: YAML 1.1, or open the example with that setting:
The Norway problem, and the letters that are safe
YAML 1.1’s boolean type reads yes, no, on, off, true and false in several capitalisations as booleans, so the country code NO loads as False in PyYAML. YAML 1.2’s core schema only accepts true and false, so the same line is the string "NO".
The single letters y and n stay strings in PyYAML, and True with a capital T is a boolean in both versions. Keys are affected too; the converter’s FAQ shows how on: in a GitHub Actions workflow becomes True in PyYAML.
Numbers that change on the way
0755: octal 493 in YAML 1.1 (int type), decimal 755 in YAML 1.2, which writes octal as0o755. A file mode written for one version is wrong in the other.0800: not valid octal, so YAML 1.1 and PyYAML keep it as the text'0800', while YAML 1.2 reads 800. Zip codes and IDs with leading zeros belong in quotes.1.10: a number in every version. The converter keeps the digits1.10in the JSON, but any program that parses that JSON into a float sees 1.1. A version number like this must be quoted, or1.10and1.1become the same release.1e3: a number in YAML 1.2, text in YAML 1.1, whose float type needs a decimal point and a signed exponent (1.0e+3).22:22and1:30: base-60 numbers in YAML 1.1 (1342 and 90), text in YAML 1.2. Port mappings and times are the usual victims.12345678901234567890: the converter writes the same digits, and the JSON is valid. But RFC 8259 only promises that integers within ±(253−1) are read the same everywhere; JavaScript’sJSON.parseturns this one into12345678901234567000. Large IDs are safer as strings.
For how Velkaro’s JSON diff compares such numbers (1.10 equals 1.1, long integers are compared exactly), see the comparison guide.
Dates, null and infinity
An unquoted 2026-11-08 is a date in YAML 1.1 (timestamp type) and PyYAML returns a Python date. JSON has no date type, so the converter’s 1.1 mode writes "2026-11-08T00:00:00.000Z": midnight UTC, which a program in another time zone may show as the day before. In YAML 1.2 it stays the text "2026-11-08".
~ and an empty value are null in both versions. .inf and .NaN are valid YAML floats, but JSON does not permit them, so the converter writes null and lists the paths in its report.
What to quote before you convert
Quote a value if it is meant to be text and it is any of these: yes/no/on/off in any case, a number with a leading zero, a version number, anything with a colon between digits, a date, a long ID, or ~, null or an empty string. The JSON to YAML converter goes further: it quotes any string that either version would read as something else, so it also quotes 0x1F, +5, 1_000 and True. Given every value above as a JSON string, all 26 came out quoted, and its round-trip check confirmed that YAML 1.2 and YAML 1.1 both read them back as the same strings:

Open this example in the converter →
With Quote for YAML 1.1 too turned off, it quotes only the 14 values YAML 1.2 itself would misread, and its round-trip line warns that a YAML 1.1 parser would read different data. Use that setting only when you know every reader of the file is YAML 1.2.
| Text | Both versions | YAML 1.2 only |
|---|---|---|
NO | "NO" | NO |
yes | "yes" | yes |
0755 | "0755" | "0755" |
0800 | "0800" | "0800" |
1.10 | "1.10" | "1.10" |
22:22 | "22:22" | 22:22 |
2026-11-08 | "2026-11-08" | 2026-11-08 |
12345678901234567890 | "12345678901234567890" | "12345678901234567890" |
Sources
- YAML 1.2.2 specification: superset of JSON (1.2), core schema tag resolution (10.3.2)
- YAML 1.1 Boolean type: yes/no/on/off and y/n
- YAML 1.1 Integer type: octal, base 60, underscores
- YAML 1.1 Floating-Point type: dot and signed exponent
- YAML 1.1 Timestamp type: dates
- RFC 8259, The JSON Data Interchange Format: no Infinity/NaN, interoperable integer range (section 6)
All pages were read on 10 November 2026. Converter outputs on this page are generated by the same code that runs in the converter; PyYAML results come from PyYAML 6.0.3 on Python 3.