December 5, 2026

JSON vs YAML vs TOML: The Config File Where Norway Became False

Three differently structured documents pinned side by side on a board

A YAML file listed four country codes: [GB, IE, NO, SE]. Python’s PyYAML library read it back as ['GB', 'IE', False, 'SE']. In the same file, python_version: 3.10 came back as the number 3.1, file_mode: 0755 as 493 and duration: 22:22 as 1342. None of those are bugs in the usual sense; each follows a rule written into the YAML 1.1 type definitions. JSON and TOML would have refused or kept the values intact, and each pays for that strictness in other ways. Every result below came from running the formats through real parsers.

Video: Kahan Data Solutions on YouTube

Three formats, three goals

JSON: data interchange

JSON is defined by RFC 8259, published in December 2017. It has objects, arrays, strings, numbers, booleans and null, and almost nothing else. It is the native language of web APIs, and nearly every programming language can read it without extra libraries.

YAML: human-friendly, with a lot of inference

YAML replaces brackets with indentation and lets most strings go unquoted. The current specification, YAML 1.2.2, was published in October 2021; its introduction says the 1.2 specification’s “primary focus was making YAML a strict superset of JSON.” Docker Compose, Kubernetes and GitHub Actions all use it for their configuration files.

TOML: config files with obvious meaning

TOML 1.0.0 states its aim plainly: “TOML aims to be a minimal configuration file format that’s easy to read due to obvious semantics,” designed to map “unambiguously to a hash table.” Python projects declare their settings in pyproject.toml, and Rust’s Cargo uses it too.

A 3D render of a red ink pad beside multiple stamped impressions

YAML’s type guessing

The test file

countries: [GB, IE, NO, SE]
python_version: 3.10
file_mode: 0755
duration: 22:22
answer: yes
date: 2025-12-30

What PyYAML returned

{'countries': ['GB', 'IE', False, 'SE'], 'python_version': 3.1,
 'file_mode': 493, 'duration': 1342, 'answer': True,
 'date': datetime.date(2025, 12, 30)}

Where each surprise comes from

The YAML 1.1 boolean type definition accepts not just true and false but y, yes, n, no, on and off in several capitalizations, so Norway’s NO became False. The YAML 1.1 integer definition treats a leading zero as base 8, so 0755 became 493, and includes a base-60 form for numbers separated by colons, so 22:22 became 22 × 60 + 22 = 1342. And 3.10 looks like a decimal, so it’s stored as the float 3.1, losing the zero that made it Python 3.10 rather than 3.1.

YAML 1.2 fixed the booleans

The 1.2.2 spec’s core schema narrows booleans to “true | True | TRUE | false | False | FALSE” and writes octal with an explicit 0o prefix. Under those rules, NO stays a string and 0755 stays a plain decimal. The catch is that a file doesn’t announce which rules its reader follows, and PyYAML’s output in this test followed the 1.1 definitions.

The fix that always works

Quoting removes the guessing. countries: [GB, "NO"] and python_version: "3.10" came back as ['GB', 'NO'] and '3.10'. In YAML, any value that should stay text but could look like something else deserves quotes.

What YAML can do that the others can’t

YAML’s extra syntax isn’t only a source of traps. Anchors and aliases let one block reuse another. This file defines defaults once and overrides one value:

defaults: &d
  retries: 3
  timeout: 30
prod:
  <<: *d
  timeout: 60

PyYAML returned prod as {'retries': 3, 'timeout': 60}. Neither JSON nor TOML has a way to say “the same as that, except.” YAML also handles long text cleanly: a | block kept two lines as 'line one\nline two\n', while > folded them into 'line one line two\n'.

Loading YAML safely

YAML can describe more than plain data, including language-specific objects. PyYAML’s documentation is blunt: “It is not safe to call yaml.load with any data received from an untrusted source!” and it points to yaml.safe_load instead. In the test, safe_load refused a document tagged to run a shell command, raising ConstructorError: could not determine a constructor for the tag 'tag:yaml.org,2002:python/object/apply:os.system'. JSON and TOML parsers have no equivalent feature to misuse.

JSON’s strictness

What JSON refused

Python’s json module rejected three things people write all the time:

Input Result
{"a": 1,} Illegal trailing comma before end of object
{"a": 1} // note Extra data
{'a': 1} Expecting property name enclosed in double quotes

No trailing commas, no comments, no single quotes. That rigidity makes JSON awkward to edit by hand and excellent for machines, since there’s only one way to write anything.

Big numbers

RFC 8259 warns that numbers are only reliably exchanged within the range of a double-precision float, and that integers in “the range [-(253)+1, (253)-1] are interoperable.” The test proved the point. Python parsed {"big": 9007199254740993} exactly. Node.js returned 9007199254740992, off by one, because JavaScript stores every JSON number as a double. Database IDs and large counters that pass through JavaScript should travel as strings.

Duplicate keys

The same RFC says names within an object “SHOULD be unique” and warns that otherwise “the behavior of software that receives such an object is unpredictable.” Python quietly kept the last value: {"a":1,"a":2} became {'a': 2}. PyYAML did the same with a repeated YAML key.

Coffee in black ceramic teacup

TOML’s middle ground

The test file

title = "x"
version = "3.10"
mode = 0o755
port = 8080
release = 2025-12-30
ratio = 3.10

[server]
host = "nas.home.arpa"

What Python’s tomllib returned

{'title': 'x', 'version': '3.10', 'mode': 493, 'port': 8080,
 'release': datetime.date(2025, 12, 30), 'ratio': 3.1,
 'server': {'host': 'nas.home.arpa'}}

Strings are always quoted, so "3.10" stays text. Octal needs an explicit 0o. Dates are a real type, not a guess. Every value’s type is visible from how it’s written.

What TOML refused

x = yes failed with Invalid value; TOML’s booleans are lowercase true and false only. A key defined twice failed with Cannot overwrite a value, which the spec requires: “Defining a key multiple times is invalid.” That’s the opposite of JSON and YAML in this test, which kept the last value without a word.

Lists of tables and deep nesting

TOML writes a list of objects with double brackets, repeating the header for each item:

[[servers]]
name = "nas"
port = 22

[[servers]]
name = "pi"
port = 2222

[database.replica.settings]
timeout = 5

tomllib returned servers as a list of two dictionaries and turned the dotted header into three levels of nesting: {'database': {'replica': {'settings': {'timeout': 5}}}}. It works, but every level of depth means a longer header to read, which is why deeply nested structures such as Kubernetes manifests read more naturally in YAML. TOML is at its best when most settings sit one or two levels down.

Reading it in Python

The tomllib documentation says the module was “Added in version 3.11” with TOML 1.0.0 support, and notes that it “does not support writing TOML.” Programs that need to write TOML use a third-party package such as tomli-w.

Side by side

The differences that matter day to day

JSON YAML TOML
Comments No # #
Trailing commas Error n/a Allowed in arrays, error in inline tables
Unquoted strings No Yes, with type guessing No
Booleans true/false Depends on parser version true/false only
Dates No (strings) Yes Yes
Duplicate keys Last wins (Python) Last wins (PyYAML) Error
Deep nesting Brackets Indentation Gets awkward

Where each one fits

JSON fits data moving between programs: API responses, logs, anything generated and parsed by code. YAML fits long, deeply nested configuration that people edit often, like Compose and Kubernetes files, as long as ambiguous values are quoted. TOML fits flat-to-moderately nested settings files where a wrong type would cause trouble, like project metadata and application config.

Rows of old filing cabinets with labels

Avoiding the traps

Rules that prevent most surprises

  • In YAML, quote anything that could be read as a boolean, number, date or time: country codes, version numbers, zip codes, file modes, times.
  • In JSON, send large integers as strings if any JavaScript code will touch them.
  • Validate config files in CI or with a schema, so a duplicate key or wrong type fails loudly instead of quietly.
  • Check which YAML version a tool’s parser follows before trusting unquoted values.

Convert carefully

Moving a file between formats is where these differences bite. A YAML file converted to JSON by a parser that follows 1.1 rules carries false where NO used to be, permanently. Loading, printing and checking the converted data before deleting the original catches it. A round trip is the quickest check: load the original, write it out in the new format, load that back, and compare the two Python dictionaries. If they differ, a type changed somewhere along the way, and the comparison shows exactly which key.

Sources

  • RFC 8259, The JavaScript Object Notation (JSON) Data Interchange Format (December 2017), RFC Editor: https://www.rfc-editor.org/rfc/rfc8259
  • YAML Ain’t Markup Language version 1.2.2 (October 2021), yaml.org: https://yaml.org/spec/1.2.2/
  • Boolean Language-Independent Type for YAML 1.1, yaml.org: https://yaml.org/type/bool.html
  • Integer Language-Independent Type for YAML 1.1, yaml.org: https://yaml.org/type/int.html
  • TOML v1.0.0, toml.io: https://toml.io/en/v1.0.0
  • PyYAML Documentation, pyyaml.org: https://pyyaml.org/wiki/PyYAMLDocumentation
  • tomllib — Parse TOML files, Python documentation: https://docs.python.org/3/library/tomllib.html

920 Posts

Peter Kalafatis writes and edits X9M8. He holds a bachelor's degree from LIU Post and a master's in Media Studies from The New School, with academic work in the philosophy of science, human behavior, AI, and memetics.

View All Posts

Leave a Reply

Your email address will not be published. Required fields are marked *