Developer Tools

JSON vs YAML: Parser Differences That Break Real Configs

JSON vs YAML tested: one file through PyYAML, ruamel.yaml, js-yaml and yaml, YAML 1.1 vs 1.2 booleans and octals, a parse benchmark, and when to use each.

TechLogHub Editorial
December 3, 2026
14 min read
0 views

Share Article

TechLogHub cover: country: NO read as False by a YAML 1.1 parser and as the string NO by YAML 1.2 and JSON

JSON vs YAML: Parser Differences That Break Real Configs

Quick answer: Use JSON when machines write and read the data: APIs, lockfiles, anything parsed in a hot path. Use YAML when humans edit the file by hand and want comments, but pin down which YAML version your parser implements. The same YAML file can mean different things in different libraries. In our tests PyYAML 6.0.3 read country: NO as False, on: as the boolean key True, and 012 as 10, while js-yaml 5.5.0, yaml 2.9.1 and ruamel.yaml 0.19.1 read them as "NO", "on" and 12. YAML was also 16 to 283 times slower to parse than JSON in our benchmark.

"JSON or YAML?" is usually framed as a taste question: braces versus indentation. That framing hides the real difference. JSON has one grammar, and every mainstream parser agrees on what a document means. YAML has two major versions in active use, 1.1 and 1.2, and they disagree about basic scalars like yes, NO, on and 012. Many popular libraries still implement 1.1 behaviour by default.

So the useful question is not which syntax you prefer. It is whether every tool that reads this file will agree on what it says. This guide covers the version split, the results of the same file run through four YAML parsers and a fifth mode, a benchmark, duplicate keys, merge keys, and a decision table. Every result below was produced on 3 December 2026 with the versions listed.

The short version: grammar versus guesswork

JSON is defined by RFC 8259. It has six value types: object, array, string, number, true/false and null. Strings are always quoted. There are no comments, no anchors and no implicit typing, so a parser never has to guess whether NO is a string. It cannot be anything else, because unquoted NO is not valid JSON at all.

YAML resolves types from plain, unquoted text. 42 becomes an integer, true becomes a boolean, 2026-12-03 may become a date. That is what makes YAML pleasant to write by hand. It is also where the trouble starts, because the rules for that resolution changed between versions.

JSONYAML
SpecRFC 8259YAML 1.2.2 (2021); many parsers still follow 1.1
CommentsNoYes (#)
Strings need quotesAlwaysUsually not
Implicit typingNoneYes; rules differ between 1.1 and 1.2
Duplicate keys"SHOULD be unique"; behaviour unpredictable otherwiseError in most parsers we tested; PyYAML keeps the last value
Anchors and reuseNoAnchors and aliases; merge keys vary by parser
Parse speed (our benchmark)Fastest16–283× slower than JSON
Superset relationshipn/aYAML 1.2 is a superset of JSON

YAML 1.1 versus 1.2: the change most people missed

YAML 1.2 was released in 2009, and the current revision, 1.2.2, was published on 1 October 2021. The official changes page calls the switch to a new core schema "the most significant difference between YAML 1.1 and YAML 1.2." Under that schema:

  • "Only true and false strings are parsed as booleans (including True and TRUE); y, yes, on, and their negative counterparts are parsed as strings."
  • "Underlines _ cannot be used within numerical values."
  • "Octal values need a 0o prefix; e.g. 010 is now parsed with the value 10 rather than 8."
  • "The binary and sexagesimal integer formats have been dropped."
  • The !!pairs, !!omap, !!set, !!timestamp and !!binary types were dropped.
  • "The merge << and value = special mapping keys have been removed."

The other major change was "to make sure that YAML 1.2 is a valid superset of JSON." Every valid JSON document is meant to be a valid YAML 1.2 document with the same meaning.

That is the spec. Libraries are another matter. The maintained Go library, go-yaml, is unusually honest about it. Its README says it "supports most of YAML 1.2 and retains selected YAML 1.1 behavior for compatibility, including legacy octal notation and yes/no booleans when loading into typed Go bools." Its v4.0.0 release came out on 4 November 2026. Other libraries are less explicit, which is why we tested them.

Worked example: one file, five parsers

We wrote a ten-line file that hits each change listed above:

country: NO
enabled: yes
on: push
port: 0o14
legacy_octal: 012
ver: 3.10
sexagesimal: 1:30
big: 1_000
nothing: ~
date: 2026-12-03

Then we loaded it with PyYAML 6.0.3 (yaml.safe_load) and ruamel.yaml 0.19.1 (YAML(typ='safe', pure=True)) on Python 3.13.18, and with js-yaml 5.5.0 (load) and yaml 2.9.1 (parse, plus parse(src, { version: '1.1' })) on Node v22.23.5. All default settings except the explicit version flag. The raw output:

PyYAML safe_load:     country=False  enabled=True  True='push'  port='0o14'
                      legacy_octal=10  ver=3.1  sexagesimal=90  big=1000
                      nothing=None  date=datetime.date(2026, 12, 3)
ruamel (1.2 default): country='NO'  enabled='yes'  on='push'  port=12
                      legacy_octal=12  ver=3.1  sexagesimal='1:30'  big=1000
                      nothing=None  date=datetime.date(2026, 12, 3)
js-yaml load:         country="NO"  enabled="yes"  on="push"  port=12
                      legacy_octal=12  ver=3.1  sexagesimal="1:30"  big="1_000"
                      nothing=null  date="2026-12-03"
yaml parse:           country="NO"  enabled="yes"  on="push"  port=12
                      legacy_octal=12  ver=3.1  sexagesimal="1:30"  big="1_000"
                      nothing=null  date="2026-12-03"
yaml version 1.1:     country=false  enabled=true  true="push"  port="0o14"
                      legacy_octal=10  ver=3.1  sexagesimal=90  big=1000
                      nothing=null  date=Date(2026-12-03T00:00:00.000Z)

As a table:

InputPyYAML 6.0.3ruamel.yaml 0.19.1js-yaml 5.5.0yaml 2.9.1yaml 2.9.1 (1.1 mode)
country: NOFalse"NO""NO""NO"false
enabled: yesTrue"yes""yes""yes"true
on: push (key)key Truekey "on"key "on"key "on"key "true"
port: 0o14string "0o14"121212string "0o14"
legacy_octal: 0121012121210
ver: 3.103.13.13.13.13.1
sexagesimal: 1:3090"1:30""1:30""1:30"90
big: 1_00010001000"1_000""1_000"1000
nothing: ~NoneNonenullnullnull
date: 2026-12-03date objectdate objectstringstringDate object

What this means in practice

PyYAML behaves like YAML 1.1. Its output matches the yaml library in explicit 1.1 mode on every boolean, octal and sexagesimal row. In practice that means it turns the ISO country code for Norway into False.

The on: key is the nastiest case. PyYAML turns the key itself into the boolean True. A script that loads a CI workflow file with PyYAML and then looks up data["on"] gets a KeyError, because the key is now True. Nothing warns you.

3.10 is a float everywhere. Every parser, in every mode, read ver: 3.10 as 3.1. This is not a 1.1 versus 1.2 issue. It is plain YAML number resolution, and it bites anyone who lists runtime versions like Python 3.10 unquoted. Quote version strings.

Even 1.2 parsers disagree. ruamel.yaml accepted 1_000 as 1000 while js-yaml and yaml kept it as a string, despite the 1.2 change list saying underscores are not allowed in numbers. ruamel.yaml and PyYAML produced date objects while both JavaScript libraries returned a plain string. "Uses YAML 1.2" does not mean "gives the same result as every other 1.2 parser."

JSON has none of these rows. Run the same data through any JSON parser and every value means exactly what it says, because strings carry quotes. If you need YAML, quote anything that is not obviously a number or a boolean. country: "NO" is the same in every parser we tried.

To see how your own config converts, paste it into our YAML to JSON converter and read the output. The quoting tells you exactly what each value became. Going the other way, the JSON to YAML converter shows where a YAML emitter adds quotes to protect values like NO.

Speed and size: a benchmark

Config files are small, so parse speed rarely matters for them. It matters a great deal when YAML is used as a data format: fixtures, large manifests, data exports. We generated 20,000 records, each with an id, a name, a three-item tag array, a number, a boolean and a nested object, and serialised them both ways.

Node v22.23.5 (mean of 5 runs, 3 for yaml)
JSON bytes 2,644,075   YAML bytes 2,884,074
JSON.parse                    11.3 ms
js-yaml load (YAML text)     185.1 ms
yaml parse (YAML text)     2,553.9 ms
js-yaml load (JSON text)     154.3 ms

Python 3.13.18
json.loads                         30 ms
yaml.safe_load (pure Python)    8,501 ms
yaml.load(Loader=CSafeLoader)   2,346 ms

Three findings:

  1. The YAML file was 9% larger. Block-style YAML drops braces and quotes but adds indentation and a - per list item, and for deeply nested arrays the indentation wins.
  2. YAML parsing was 16× (js-yaml) to 226× (yaml) slower in Node, and 78× (PyYAML with LibYAML) to 283× (pure-Python PyYAML) slower in Python. If you use PyYAML for anything large, make sure the C-accelerated CSafeLoader is available. In our run it was 3.6× faster than the default pure-Python loader.
  3. Parsing JSON with a YAML parser is still slow. js-yaml took 154 ms on the JSON text versus 11 ms for JSON.parse. YAML being a superset of JSON does not make a YAML library a good JSON parser.

The benchmark measures parsing only, on one machine; treat the ratios as an order of magnitude, not a spec.

Duplicate keys and merge keys

Duplicate keys

RFC 8259 says object names "SHOULD be unique", and that when they are not, "the behavior of software that receives such an object is unpredictable. Many implementations report the last name/value pair only." That is a SHOULD, not a MUST, so {"a":1,"a":2} is technically valid JSON. YAML's changes page notes that revision 1.2.1 added a paragraph about JSON compatibility "in the presence of duplicate mapping keys".

Here is what each library did with a duplicate key:

JSON.parse('{"a":1,"a":2}')   → {"a":2}            (last wins, silently)
PyYAML  safe_load('a: 1\na: 2') → {'a': 2}         (last wins, silently)
js-yaml load(...)             → YAMLException: duplicated mapping key
yaml    parse(...)            → error DUPLICATE_KEY
ruamel  load(...)             → DuplicateKeyError

Three of the four YAML libraries refuse the file. JSON.parse and PyYAML take the last value without a word. In a long config file, a duplicated key is almost always a copy-paste mistake, so the YAML libraries that throw are doing you a favour. If you rely on JSON for configs, add a linter that rejects duplicate keys, because the parser will not.

Merge keys

YAML anchors (&name) and aliases (*name) let you reuse a block. The merge key << goes further and merges a mapping into another. It was a YAML 1.1 type, and the 1.2 change list removed it. Libraries split on it:

base: &b
  image: node:22
  retries: 2
job:
  <<: *b
  retries: 5
PyYAML 6.0.3        job = {'image': 'node:22', 'retries': 5}
ruamel.yaml 0.19.1  job = {'image': 'node:22', 'retries': 5}
js-yaml 5.5.0       job = {"<<": {"image": "node:22", "retries": 2}, "retries": 5}
yaml 2.9.1          job = {"<<": {"image": "node:22", "retries": 2}, "retries": 5}
yaml 2.9.1 merge:true → {"image": "node:22", "retries": 5}

The two Python libraries merged. Both JavaScript libraries kept << as an ordinary key by default, which yields a job object that has no image at all unless the code knows to look under <<. yaml merges when you pass merge: true. If your tooling relies on merge keys, test the exact library and version that reads the file in production.

Catching the traps before they ship: yamllint

You do not have to memorise the 1.1 rules. A linter can flag most of them in CI. We ran yamllint 1.38.0 against the same ten-line file, plus a three-line file with a duplicated key, using this config:

# .yamllint.yaml
extends: default
rules:
  truthy:
    allowed-values: ["true", "false"]
    check-keys: true
  octal-values:
    forbid-implicit-octal: true
    forbid-explicit-octal: false
  key-duplicates: enable
  document-start: disable

The output, unedited:

$ yamllint -c .yamllint.yaml cases.yaml dup.yaml
cases.yaml
  1:10      warning  truthy value should be one of [false, true]  (truthy)
  2:10      warning  truthy value should be one of [false, true]  (truthy)
  3:1       warning  truthy value should be one of [false, true]  (truthy)
  5:18      error    forbidden implicit octal value "012"  (octal-values)

dup.yaml
  3:1       error    duplication of key "a" in mapping  (key-duplicates)

$ echo $?
1

That is a good result. The linter caught NO, yes, the on: key (because check-keys is on), the implicit octal 012, and the duplicate key. The non-zero exit code fails a CI job.

It also shows the limits. yamllint said nothing about ver: 3.10, sexagesimal: 1:30 or big: 1_000. Those are valid YAML that simply resolve to surprising values, and no rule in this config flags them. A linter narrows the gap; it does not close it. The two habits that close it are quoting non-trivial strings and validating the parsed result against a schema.

Notice too that the truthy findings came out as warnings, not errors. In a pipeline that only fails on errors, a country: NO would pass. If you adopt yamllint for this purpose, set level: error on the truthy rule so the trap cannot slip through.

A safe-YAML checklist

Distilled from the tests above:

  • Quote every string that a parser might read as something else: country and language codes, version numbers, anything with a leading zero, yes/no/on/off, times like 1:30.
  • Write booleans only as true or false, in lower case.
  • Use 0o for octal if you mean octal, and quote values like file modes if your tool expects a string.
  • Avoid merge keys (<<) in files read by more than one library, or test every reader.
  • Run a linter with duplicate-key and truthy checks in CI, at error level.
  • Validate the loaded data against a schema in the application, so a wrong type fails at startup.

None of this is needed for JSON, which is the strongest argument for it in machine-written files.

Which to use: a decision table

SituationPickWhy
API request and response bodiesJSONOne grammar, native in browsers, fastest parse
Lockfiles, generated manifests, cachesJSONMachines write them; no ambiguity, no comments needed
Large data files or fixturesJSON (or JSON Lines)16–283× faster to parse in our benchmark
Hand-edited config with commentsYAML, values quotedComments and readability; quoting removes 1.1 versus 1.2 drift
Config read by tools in several languagesJSON, or YAML with a schema checkOur five parser modes disagreed on 8 of 10 rows
CI workflows, Kubernetes, ComposeYAML (the tool decides)The format is fixed; quote risky scalars and validate with the tool's own linter
Config that must be typed in codeEither, validated at load timeGenerate types or a schema; see below

Whatever you pick, validate the parsed result instead of trusting the file. Paste a sample into our JSON to Zod tool to get a starting schema, or the JSON to TypeScript tool for interfaces. A schema that expects country: z.string() turns PyYAML's False into a loud error at startup instead of a silent wrong value. Our Zod production guide covers running those checks cheaply.

Limits of this comparison

A few things this article does not settle, so you can judge how far the results travel:

  • We tested defaults. Most libraries have options that change behaviour. PyYAML can be given custom resolvers, and yaml has a version flag, as shown. A team that configures its parser carefully can avoid most of these problems. Most teams do not.
  • We did not test every library. Go, Rust, Java and Ruby parsers have their own defaults. go-yaml documents its 1.1 holdovers. For the rest, run the ten-line file above through your own stack. It takes two minutes.
  • The benchmark is one machine and one data shape. Ratios will change with nesting depth, string length and hardware. The direction will not: JSON parsers are simpler and heavily optimised.
  • JSON has real pain points. No comments, no trailing commas, and noisy diffs for hand-edited files. Variants like JSONC exist for exactly that reason. If a human edits the file every day, YAML with quoted values may still be the better trade.

To compare two versions of a config after a format change, run the old and new parsed output through a text diff checker, and keep the JSON formatter open to make minified JSON readable. Both run in the browser. Browse more free developer tools for other conversions.

FAQ

Is YAML a superset of JSON?

YAML 1.2 is. The YAML 1.2 changes page says one of the major goals was to make YAML a valid superset of JSON, so a valid JSON document is also valid YAML 1.2. Older YAML 1.1 parsers do not guarantee that, and even a 1.2 parser was more than 13 times slower than JSON.parse on JSON text in our test.

Why does YAML turn NO into false?

Because YAML 1.1 treats y, yes, n, no, on and off as booleans. YAML 1.2 changed that so only true and false are booleans, but many libraries keep the 1.1 behaviour. In our test PyYAML 6.0.3 read country: NO as False. Quote the value as "NO" and every parser keeps it as a string.

Which Python YAML library follows YAML 1.2?

In our tests ruamel.yaml 0.19.1 followed YAML 1.2 for booleans, octals and sexagesimal numbers, while PyYAML 6.0.3 behaved like YAML 1.1. Test with your own files, because even 1.2 libraries differed on details such as underscores in numbers and date handling.

Is JSON faster to parse than YAML?

Yes, by a wide margin in our benchmark. On a 2.6 MB file of 20,000 records, JSON.parse took 11.3 ms while js-yaml took 185 ms and the yaml package took about 2.6 seconds. In Python, json.loads took 30 ms against 2.3 seconds for PyYAML with its C loader.

Should I quote strings in YAML?

Quote anything that is not obviously a number or boolean, especially country codes, version numbers like 3.10, values such as yes, no, on and off, and numbers with leading zeros. Quoting makes the value a string in every parser and removes the YAML 1.1 versus 1.2 differences.

Can JSON have comments?

No. RFC 8259 JSON has no comment syntax. If you need comments in a hand-edited file, use YAML with quoted values, or a JSON variant that your tool explicitly supports.


All parser results and benchmarks were produced on 3 December 2026 with the library versions named above. Library defaults change between releases, so rerun the test file against the versions you actually deploy.

Stay Updated

Get the next deep dive in your inbox

Subscribe for product analysis, engineering explainers, and practical guides published on TechLogHub.

See what launched this week

One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.

JSON vs YAML: Parser Differences That Break Configs | Developer Tools