A practical comparison of the four most popular data serialization formats — with real-world use cases for each.
| Feature | JSON | XML | YAML | TOML |
|---|---|---|---|---|
| Human readable | Yes | Moderate | Yes | Yes |
| Comments | No | Yes | Yes | Yes |
| Schema support | Yes | Yes | Partial | No |
| Browser native | Yes | Yes | No | No |
Best for: REST APIs, web apps, data interchange.
JSON is the default for HTTP APIs. Every language has a native parser, it's compact, and browsers understand it natively.
{ "host": "localhost", "port": 5432 }
Best for: Enterprise systems, SOAP APIs, document formats (SVG, RSS).
<config>
<host>localhost</host>
<port>5432</port>
</config>
Best for: Config files (Docker Compose, Kubernetes, CI/CD).
host: localhost
port: 5432
Best for: Application config (Rust's Cargo.toml, Python's pyproject.toml).
[database]
host = "localhost"
port = 5432