YAML & JSON: Which Config Format Fits—and How to Convert
2025-05-20
YAML 1.2 targets JSON compatibility—valid JSON should parse as YAML. Ops configs favor YAML; apps favor JSON—know the pitfalls when converting.
Core differences
JSON: no comments, double-quoted keys, one canonical shape. YAML: indentation, # comments, flexible scalars.
{ "server": { "port": 8080 } }server:
port: 8080Which for config files?
Hand-edited ops config (K8s, Docker, CI) → YAML. Generated manifests and app interchange → JSON.
Conversion traps
yes/no as booleans, version strings as numbers, anchors absent in JSON, tabs illegal in YAML.
CLI conversion
yq, js-yaml, PyYAML—always JSON.parse after conversion to catch silent type changes.
Practical Kubernetes tips
Keep YAML in repo; convert in CI when a JSON-only consumer needs it. Don't hand-write huge JSON manifests.
Summary
Humans → YAML; machines → JSON. Pin tool versions and validate after every transform.