JSON vs YAML vs TOML vs XML: which format should you use?
JSON, YAML, TOML, and XML all describe structured data, but each wins at a different job. Here's how they compare on syntax, comments, and types — with the best use case for each.
JSON vs YAML vs TOML vs XML at a glance
JSON, YAML, TOML, and XML all describe structured data, but each is built for a different job. JSON is the lingua franca of web APIs; YAML is the most human-friendly for hand-edited config; TOML trades flexibility for predictable, unambiguous config; and XML remains the choice when you need attributes, mixed content, namespaces, or schema validation. The table below compares them on the decisions that actually matter:
| JSON | YAML | TOML | XML | |
|---|---|---|---|---|
| Comments | No | Yes | Yes | Yes |
| Syntax | Braces | Indentation | Key = value | Tags |
| Native dates | No | Yes | Yes | No (text) |
| Deep nesting | Great | Great | Awkward | Great |
| Attributes | No | No | No | Yes |
| Verbosity | Low | Lowest | Low | High |
| Best at | APIs | Config | Config | Documents |
The same data in all four formats
// JSON
{ "name": "api", "port": 8080, "tags": ["web", "prod"] }
# YAML
name: api
port: 8080
tags:
- web
- prod
# TOML
name = "api"
port = 8080
tags = ["web", "prod"]
<!-- XML -->
<service name="api">
<port>8080</port>
<tags><tag>web</tag><tag>prod</tag></tags>
</service>Which one should you use?
- Pick JSON for APIs, data interchange, and anything machine-to-machine. It's universally supported and unambiguous — at the cost of no comments.
- Pick YAML for config a human edits often (CI pipelines, Kubernetes, app settings). Comments and minimal punctuation make it readable — but watch the indentation and surprising type coercions.
- Pick TOML for config where you want zero ambiguity (Rust's Cargo, Python's pyproject). Indentation never changes meaning and types are explicit; deep nesting is where it gets clumsy.
- Pick XML when you need attributes, mixed text-and-markup, namespaces, or XSD schema validation — or when an enterprise/SOAP system requires it.
The Norway problem (why TOML exists)
YAML's convenience has a famous sharp edge: a bare value it thinks is a boolean gets coerced. The country code NO becomes false, yes becomes true, and a version like 1.20 loses its trailing zero. Quoting avoids it ("NO"), but it's an easy trap. TOML was designed partly to eliminate this class of surprise — its types are always explicit.
Convert between them in one click
Yellorn parses JSON, YAML, TOML, and XML into one shared structure and re-serializes to another via the Convert to… menu. If the target can't represent your data faithfully — TOML has no null type, XML needs a single root — it warns you first. See cross-format conversion for the details. The conversion runs in your browser and a single undo restores the original.
Frequently asked questions
What is the difference between JSON and YAML?
JSON uses explicit braces and brackets and supports no comments, which makes it ideal for machine-to-machine APIs. YAML uses indentation instead of braces and allows comments, which makes it friendlier for human-edited config files. YAML is a superset of JSON, so any JSON document is also valid YAML.
Is TOML better than YAML for config files?
TOML trades YAML's flexibility for predictability. Its indentation never changes meaning, its types are explicit, and it has a first-class date type, so it avoids YAML's surprising coercions (the classic 'Norway problem' where the country code NO becomes false). TOML shines for flat-to-moderate config; deeply nested data still reads better in YAML or JSON.
When should I still use XML?
Reach for XML when you need attributes alongside element content, mixed text-and-markup (documents), namespaces, or schema validation via XSD — or when you're integrating with an enterprise/SOAP system that mandates it. For most modern APIs and configs, JSON, YAML, or TOML are lighter choices.
Which format has the best data-type support?
JSON covers strings, numbers, booleans, null, arrays, and objects. TOML adds native dates and times. YAML adds dates plus anchors/aliases for reuse. XML is technically all text — every value is a string until a schema gives it a type. Pick based on whether native dates and comments matter to you.
Can I convert between JSON, YAML, TOML, and XML?
Yes. Yellorn parses any of them into one shared structure and re-serializes to another in one click, warning you first if the target format can't represent the data faithfully (for example, TOML has no null type). The conversion runs in your browser and a single undo restores the original.
Related
Where to go next
Try a fix in the editor or browse more articles.