Comparison

JSON vs YAML vs TOML — When to Use What

What each format is good at, what each is bad at, and how to pick the right one for a config file, an API payload, or a data file.

ByMayank RaiUpdated May 4, 2026

Three text formats dominate developer tooling: JSON for APIs, YAML for config files in cloud-native ecosystems, TOML for project metadata in newer language toolchains. Each was designed with different priorities and each has predictable strengths and pitfalls. Picking the right one for a new file is a five-minute decision that you live with for years.

This article compares the three across the dimensions that matter when you're actually using them: human readability, machine parseability, type system, comment support, tooling maturity, and gotchas.

Quick reference

# JSON
{
  "name": "Toolkiya",
  "version": "1.0.0",
  "tags": ["pdf", "image", "qr"],
  "owner": { "name": "Mayank Rai", "since": 2026 }
}

# YAML
name: Toolkiya
version: 1.0.0
tags:
  - pdf
  - image
  - qr
owner:
  name: Mayank Rai
  since: 2026

# TOML
name = "Toolkiya"
version = "1.0.0"
tags = ["pdf", "image", "qr"]

[owner]
name = "Mayank Rai"
since = 2026

Type systems

JSON has the simplest type system: strings, numbers, booleans, null, arrays, objects. Numbers are technically unbounded (the spec is a regex on text) but most parsers map them to 64-bit IEEE floats — which means precision loss for integers above 2^53. The format has no native concept of dates, binary data, or comments.

YAML adds dates, timestamps, binary data, custom tags for type extension, and references (anchors and aliases) for cross-references within a document. The richer type system is a feature for some uses (representing complex data) and a footgun for others (the famous "Norway problem" where the unquoted string NO parses as boolean false).

TOML has strings, integers, floats, booleans, datetimes (with timezone), local datetimes (without timezone), local dates, local times, arrays, and tables. Integers and floats are distinct (a TOML 3.0 is a float, 3is an integer). No null type, by deliberate design — TOML's philosophy is that absence of a key means absence of a value.

Readability

For very small files, all three are similarly readable. The differences emerge as files grow.

JSON's curly braces and quotes around every string create visual noise. A 200-line JSON file has more closing brackets than your eye can comfortably parse, and missing or extra commas produce errors that often point to the wrong line. JSON was designed for machines, and it shows.

YAML reads almost like prose. Indentation does the structural work, no quotes are needed for most strings, comments are supported. For a config file a human edits often, YAML wins on readability — which is why Kubernetes, Docker Compose, GitHub Actions, and most CI tools use it.

TOML is in between. It uses explicit punctuation (the =and brackets for tables) but doesn't require closing brackets like JSON. For project metadata where the structure is mostly flat, TOML is extremely readable. For deeply nested structures, the table syntax becomes awkward.

Pitfalls

JSON

  • No comments. Workarounds (_comment keys) are ugly and don't survive round-tripping through tools that strip unknown keys.
  • No trailing commas allowed. JSON5 fixes this but isn't standard JSON.
  • Numbers above 2^53 lose precision in most parsers.
  • Missing or extra commas produce errors that point to the wrong line.

YAML

  • Indentation-sensitive. Mixing tabs and spaces is a parse error in some parsers, silent corruption in others.
  • Boolean coercion of unquoted strings: yes, no, on, off, true, false, NO, YES, FALSE all coerce to booleans by default. The country code "NO" without quotes becomes false. YAML 1.2 narrows this to just true/false but many parsers default to 1.1 behaviour.
  • Octal numbers: 012 is 10 in some parsers, 12 in others. Always quote zip codes that might start with a zero.
  • Anchors and aliases produce non-acyclic graphs that some parsers refuse, with subtle security implications when consuming untrusted YAML.
  • The spec is large and parsers disagree on edge cases. The same file can parse differently in PyYAML, libyaml, and serde-yaml.

TOML

  • Deeply nested data is awkward. The table-of-tables syntax ([[items]]) works but doesn't scale to truly nested arrays of objects.
  • Newer than the others. Some languages still have weaker library support than for JSON or YAML.
  • Date/time types are precise but opinionated; mismatching the local-vs-zoned distinction silently breaks things.

Performance

JSON parses fastest of the three by a large margin. Modern JSON parsers (simdjson, RapidJSON) parse multiple gigabytes per second per core. The grammar is small and regular, suitable for SIMD-accelerated tokenisation.

TOML is in the middle. It's simpler than YAML and most parsers handle it efficiently, though it's still slower than JSON because the grammar is larger.

YAML is the slowest by a substantial margin. The spec is complex, parsers do significant work to disambiguate, and the cost of safe-loading (rejecting dangerous tags) is non-trivial. For a config file you read once at startup this doesn't matter; for high-throughput data interchange it does.

When to use each

Use JSON for

  • API request and response bodies. Universal language support, fast parsing, simple type system.
  • Data interchange between systems where you don't control both ends.
  • Storing structured data when you don't need comments and human editing is rare.
  • Anything that needs to be embedded in JavaScript directly.

Use YAML for

  • Configuration in cloud-native ecosystems (Kubernetes manifests, GitHub Actions, Docker Compose). The community has standardised on YAML and tooling assumes it.
  • Files humans edit frequently. Readability advantages compound when you spend hours in the file.
  • Documents with deeply nested structures. YAML's indentation handles this gracefully.

Use TOML for

  • Project metadata files (Cargo.toml, pyproject.toml). Mostly-flat structure, frequent edits, comment support.
  • Application configuration where you want explicit syntax without YAML's footguns.
  • Data files that have a tabular shape (table arrays).

Hybrid approaches

Many real systems use multiple formats. APIs speak JSON because of the ecosystem, but the same service's configuration is loaded from YAML or TOML for human-friendliness. This is fine — the formats serve different roles.

A specific anti-pattern to avoid: putting JSON inside YAML or vice-versa as embedded strings. This produces unreadable files and parse errors when the embedded content has special characters. If you find yourself doing this, you usually want a different file structure or a different format altogether.

Linting and formatting

For all three formats, automatic formatting eliminates a class of bugs. Use jq or prettier for JSON, yamllint + prettier for YAML, taplo for TOML. Run them in a pre-commit hook so you never commit mis-indented YAML or trailing-comma JSON.

For YAML specifically, schema validation (with JSON Schema, since YAML is a superset of JSON in practice) catches most bugs before they reach runtime. Tools like the GitHub Actions workflow validator do this — they know the schema and red-line invalid keys in your editor.

Tooling

For ad-hoc inspection, formatting, and conversion, browser-based tools are convenient because no upload of potentially sensitive config is needed. Toolkiya's JSON formatter and YAML to JSON converterrun entirely in your browser. Useful when the config file in your hand contains secrets and you don't want to paste it into a random web textarea.

Closing thought

The format wars are largely settled. JSON owns interchange, YAML owns cloud-native config, TOML owns language toolchains. For new files, follow the convention of the surrounding ecosystem — using TOML for a Kubernetes manifest just because you prefer it produces friction with every tool that comes after. The few cases where you actually have a choice (a new project's own config file, an internal data format) come down to whether you value explicit punctuation (TOML) or visual minimalism (YAML), and whether you need the simple type system (TOML) or the rich one (YAML).

MR

Built & maintained by Mayank Rai

Solo developer based in Lucknow, India · Last updated May 4, 2026

Format and validate JSON free

No signup, no upload to servers. Your files stay private.

Try Free on Toolkiya