velkaro.Runs in your browser

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.

By the Velkaro team · Published

The short comparison

JSONYAML
StringsAlways in double quotesQuotes optional; unquoted text may become a boolean, number, date or null
CommentsNone (RFC 8259)# to end of line (how they work)
ReuseNoneAnchors, aliases, << merge keys (guide)
Several documents per fileNoYes, split by ---
Long textOne 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.

The YAML to JSON converter's report listing 15 values read differently by YAML 1.1 parsers, each with its line number, YAML 1.2 reading and YAML 1.1 reading.
The converter’s report for the test file: 15 values that a YAML 1.1 parser reads differently, each with its line number. Click a line number to jump to it.
YAMLYAML 1.2 → JSONYAML 1.1 → JSONPyYAML 6.0.3
country: NO"NO"falseFalse
answer: no"no"falseFalse
enabled: yes"yes"trueTrue
switch: on"on"trueTrue
off_value: off"off"falseFalse
octal_old: 0755755493493
octal_new: 0o755493"0o755"'0o755'
leading_8: 0800800"0800"'0800'
binary: 0b101"0b101"55
underscore: 1_000"1_000"10001000
exp: 1e31e3"1e3"'1e3'
ports: 22:22"22:22"13421342
time: 1:30"1:30"9090
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: TruetruetrueTrue
tilde: ~nullnullNone
empty: nullnullNone
hex: 0x1F313131
version: 1.101.101.101.1
exp_signed: 1.0e+31.0e+31.0e+31000.0
inf: .infnullnullinf
nan: .NaNnullnullnan
big: 12345678901234567890123456789012345678901234567890123456789012345678901234567890
plus: +5555

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

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:

The JSON to YAML converter with the test values as JSON strings; in the visible part of the YAML output NO, no, yes, 0755 and 0800 are in quotes, and both round-trip checks pass.
JSON to YAML with every test value as a string. The report confirms the round trip for YAML 1.2 and 1.1.

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.

TextBoth versionsYAML 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"

Check your own file for type changes

Sources

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.