data · yaml · json
JSON, YAML or TOML? Converting configuration without surprises
What changes when config moves between JSON, YAML and TOML: the Norway problem, version strings, octal numbers, nulls, comments and large integers — and how to fix each.
Updated · first published · 5 min read
Key points
- Under YAML 1.1 rules, unquoted no, yes, on and off are booleans, so a country code like NO can become false. Quote strings that look like other types.
- YAML parses 1.10 as the number 1.1. Version numbers must be quoted.
- TOML has no null and requires a table at the top level, so some JSON can't be represented in TOML without changes.
- Converting to JSON drops comments, and YAML anchors and merge keys are expanded into copies.
- Integers above 2^53 lose precision in JavaScript-based JSON parsers. Store large IDs as strings.
JSON, YAML and TOML can all describe the same nested structure of maps, lists and values. Converting between them looks like it should be lossless, and for most files it is. The surprises come from the edges: values that one format reads as a different type, features that only one format has, and limits on what each can express.
This guide covers those edges, so a converted config file means what the original meant.
The three formats in one paragraph each
JSON is strict and minimal: objects, arrays, strings, numbers, true, false and null. Strings are always quoted, so a value's type is never ambiguous. It has no comments and no date type.
YAML is a superset of JSON designed for humans: indentation instead of brackets, comments, multi-line strings, anchors for reuse, and several documents in one file. Its convenience — unquoted strings — is also its main source of surprises.
TOML is designed to be obvious: key = value lines grouped under [table] headers. It has real date and time types and comments, and it's strict about types. Python's pyproject.toml, Rust's Cargo.toml, Hugo and Netlify all use it.
YAML's implicit typing
In YAML, an unquoted value's type is guessed from how it looks. Which guesses a parser makes depends on the YAML version and schema it implements — and many widely used parsers still follow YAML 1.1 rules.
The Norway problem
Under YAML 1.1, yes, no, on, off, y and n (in various capitalisations) are booleans. So this list of country codes:
countries: [GB, NO, SE]
can load as ["GB", false, "SE"]. YAML 1.2's core schema only treats true and false as booleans, but you can't always choose the parser that reads your file. The safe fix is to quote anything that is meant to be a string but looks like something else: "NO", "on", "off".
Version numbers
version: 1.10
is the floating-point number 1.1. A version string must be quoted: version: "1.10". The same applies to anything numeric-looking that isn't a number: ZIP codes like 01234, phone numbers, IDs with leading zeros.
Octal and sexagesimal numbers
YAML 1.1 reads 0755 as an octal number (493 in decimal). YAML 1.2 writes octal as 0o755 and treats 0755 as decimal 755. File permission modes in tools like Ansible are a common casualty; quote them.
YAML 1.1 also has base-60 numbers: 22:22 is the integer 1342. This is why Docker Compose's documentation recommends quoting port mappings such as "22:22".
The JSON to YAML converter quotes ambiguous strings when it writes YAML, so values like "1.10", "NO" and "0755" keep their meaning in any parser. Going the other way, the YAML to JSON converter shows exactly what a parser makes of a file — a quick way to check a config before deploying it.
Features that don't survive conversion
Comments
YAML and TOML have comments; JSON doesn't. Converting to JSON drops them, and converting back can't restore them. If the comments document why a setting exists, keep the YAML or TOML file as the source of truth and generate JSON from it, rather than converting back and forth.
Anchors, aliases and merge keys
YAML lets you define a block once and reuse it:
defaults: &defaults
timeout: 30
retries: 3
production:
<<: *defaults
timeout: 60
JSON and TOML have no equivalent, so conversion expands every alias into a full copy. The output is correct but longer, and editing the defaults later means editing every copy.
Multiple documents
A YAML file can contain several documents separated by ---, as Kubernetes manifests often do. JSON and TOML hold one document per file, so a multi-document YAML file becomes either a JSON array or several files.
Non-string keys
YAML allows keys that are numbers, booleans or even lists. JSON object keys are always strings, so 1: one becomes "1": "one".
TOML's limits
TOML is strict in two ways that matter when converting from JSON or YAML:
- No null. TOML has no null value. A key with a null value has to be omitted, or replaced with an empty string or a sentinel your application understands.
- The top level must be a table. A JSON file whose root is an array, such as
[{"id": 1}], can't be represented directly. Wrap it in a key:items = [...], which TOML writes as an array of tables,[[items]].
Converting the other way is easier, but dates need a decision: TOML has native date and datetime values, while JSON doesn't, so 2026-12-02T10:00:00Z becomes a string. The JSON to TOML and YAML to TOML converters tell you in their notes when a null had to be left out, and the TOML to JSON converter writes dates as ISO 8601 strings that any JSON consumer can parse.
Large numbers in JSON
The JSON standard doesn't limit number size, but JavaScript parses every JSON number into a 64-bit floating-point value, which represents integers exactly only up to 2^53 − 1 (9,007,199,254,740,991). Larger integers are silently rounded: 9007199254740993 comes back as 9007199254740992.
This affects any JavaScript-based tool in the pipeline, including many converters and browser dev tools. APIs that use 64-bit IDs often provide a string version of each ID for this reason. When you control the format, store large IDs as strings.
Duplicate keys
JSON's specification says object keys should be unique, and most parsers silently keep the last value when they aren't. YAML 1.2 says keys must be unique, and strict parsers reject the file. A JSON file with an accidental duplicate key may convert to YAML with one value — and you won't be told which was lost. Check for duplicates before converting files that people edit by hand.
Front matter and environment files
Static site generators put configuration at the top of each content file, as YAML, TOML or JSON front matter. The same rules apply: a post with draft: no in YAML front matter is a boolean in some generators and a string in others. When switching generators, the front matter converter rewrites the block in another format without touching the body.
.env files are simpler — every value is a string — but moving them into YAML-based systems reintroduces typing. DEBUG=no becomes DEBUG: no, which a YAML 1.1 parser reads as false. The .env converter quotes values when it writes YAML so they stay strings.
A conversion checklist
- Quote strings that look like booleans, numbers, dates or versions.
- Decide what to do with nulls before converting to TOML.
- Keep commented files as the source of truth; generate the rest.
- Expect anchors to expand into copies.
- Store large integer IDs as strings.
- Check for duplicate keys in hand-edited JSON.
- Load the converted file with the parser your application actually uses, and compare it with the original.
Each format is good at what it was designed for. Problems only appear in the space between them, and that space is small enough to check.
About the author
Abdessamad Bettal, full-stack engineer and the developer of migration.tools — free, private, browser-based tools for moving databases, data, websites and content between systems.