Skip to content

/compare/yaml/json-vs-yaml-vs-toml

JSON vs YAML vs TOML: which format for config and data

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated 2026-10-20
tool
YAML
compares
JSON vs YAML / TOML

Use JSON for data exchanged between programs (APIs, lock files): every language parses it and it has no ambiguity, but it allows no comments. Use TOML for configuration that people edit (pyproject.toml, Cargo.toml): explicit types and comments. Use YAML where the ecosystem expects it (Kubernetes, GitHub Actions, Ansible), and quote values that look like booleans or numbers.

The same data in three formats

bash
cat > app.json <<'EOF'
{"name": "api", "port": 8080, "debug": false, "hosts": ["a.example.com", "b.example.com"], "db": {"user": "app", "pool": 5}}
EOF
cat > app.yaml <<'EOF'
name: api
port: 8080
debug: false
hosts:
  - a.example.com
  - b.example.com
db:
  user: app
  pool: 5
EOF
cat > app.toml <<'EOF'
name = "api"
port = 8080
debug = false
hosts = ["a.example.com", "b.example.com"]

[db]
user = "app"
pool = 5
EOF
python -c "
import json, yaml, tomllib
a = json.load(open('app.json'))
b = yaml.safe_load(open('app.yaml'))
c = tomllib.load(open('app.toml', 'rb'))
print('identical:', a == b == c)
print(a)"

Output

identical: True
{'name': 'api', 'port': 8080, 'debug': False, 'hosts': ['a.example.com', 'b.example.com'], 'db': {'user': 'app', 'pool': 5}}

Criterion by criterion

CriterionJSONYAMLTOML
Commentsnoyes (#)yes (#)
Typesexplicit (string, number, bool, null)inferred: no, on, 1.10 can surpriseexplicit, plus dates and times
Deep nestingbraces, verbose but clearindentation, compactpossible but awkward ([a.b.c] tables)
Multiline stringsescapes only (\n)| and > block scalarstriple-quoted strings
Parser in standard librariesnearly every languageusually a third-party libraryPython 3.11+ (tomllib, read-only); others third-party
Typical useAPIs, package.json, lock filesKubernetes, CI pipelines, Ansiblepyproject.toml, Cargo.toml

Sources