YAML vs JSON vs TOML: Choosing a Config Format
Almost every tool reads a configuration file. These are the three formats you will meet most often.
JSON
JSON is strict and universal. Every language can parse it, but it does not allow comments and gets noisy with all the quotes and braces.
YAML
YAML is easy on the eyes, supports comments and is used by Kubernetes, Docker Compose and CI systems. Indentation is part of the syntax, so a misplaced space changes meaning. Some values, such as no or on, may be read as booleans.
TOML
TOML uses explicit key = value pairs and tables. It is less sensitive to whitespace than YAML and comfortable for people to edit, which is why Rust and Python projects chose it.
The same data three ways
| Format | Example |
|---|---|
| JSON | {"name": "app", "port": 8080} |
| YAML | name: app and port: 8080 on two lines |
| TOML | name = "app" and port = 8080 on two lines |
Comparison
| JSON | YAML | TOML | |
|---|---|---|---|
| Comments | No | Yes | Yes |
| Whitespace sensitive | No | Yes | No |
| Best for | APIs, data exchange | Infrastructure | App settings |
| Risk | Verbose | Indentation bugs | Less common tooling |
How to pick
Follow your ecosystem. If the tool expects YAML, use YAML. If you are free to choose and humans will edit the file, TOML is a good default. If machines write it, use JSON.