The same settings can be written in TOML, YAML or JSON. The three examples below hold identical data: parsed with Python's tomllib, PyYAML and json, they produce equal results. Convert between them with the TOML to JSON Converter, the JSON to TOML Converter, the JSON to YAML Converter and the YAML to JSON Converter.
The same configuration three ways
TOML
title = "Demo"
debug = false
ports = [8000, 8001]
[database]
host = "localhost"
max_connections = 50
YAML
title: Demo
debug: false
ports: [8000, 8001]
database:
host: localhost
max_connections: 50
JSON
{
"title": "Demo",
"debug": false,
"ports": [8000, 8001],
"database": {
"host": "localhost",
"max_connections": 50
}
}
At a glance
| TOML | YAML | JSON | |
|---|---|---|---|
| Comments | Yes (#) |
Yes (#) |
No |
| Structure | Tables and keys; no indentation rules | Indentation | Braces and brackets |
| Dates and times | Native types | Native (version-dependent) | Strings only |
| Trailing commas | Allowed in arrays | Not applicable | Not allowed |
| Duplicate keys | Error | Parser-dependent | Parser-dependent |
| Null value | None | null or ~ |
null |
| Best for | Hand-edited configuration | Large nested configuration and manifests | Data exchange and APIs |
Pitfalls
- YAML 1.1 parsers (PyYAML, many older tools) read
NOasfalse,01234as the number 668 (octal) and12:30as 750 (base 60). Quote anything meant to stay a string. - JSON has no comments and many parsers store numbers as doubles, so
9007199254740993becomes9007199254740992in JavaScript. - TOML is awkward for deeply nested data and for long arrays of mixed objects; repeating doubled-bracket table headers gets verbose.
- Duplicate keys are an error in TOML and silently overwritten in some YAML and JSON parsers.
Which to choose
- Hand-written application settings: TOML.
- Kubernetes manifests, CI pipelines and other ecosystems built on it: YAML.
- Browser, API and machine-to-machine data: JSON. Check that a document is valid with the JSON Validator & Online Debugger.