YAML's Readability Advantages
YAML uses indentation rather than brackets and quotes, making it notably more readable for humans. This is why Kubernetes, GitHub Actions, Docker Compose, and many other tools adopted YAML as their configuration format — human operators write these files regularly.
JSON's Precision Advantages
YAML's flexibility is also its weakness. The YAML specification has subtle behaviors — strings that look like numbers or booleans get automatically converted. JSON is strict: every value type is explicitly denoted, and syntax errors are immediately obvious.
The Norway Problem
A famous YAML gotcha: the country code 'NO' is parsed as a boolean false because YAML interprets certain strings as booleans. Country codes 'ON', 'OFF', 'YES', 'NO', 'TRUE', 'FALSE' all trigger this behavior in YAML 1.1. JSON's explicit quoting requirement prevents any such ambiguity.
Practical Guidance
Use YAML for configuration files that humans write and maintain: CI/CD pipelines, infrastructure definitions, application configuration. Use JSON for API responses and communication between systems: its strictness makes machine-to-machine exchange more reliable.
YAML for human-written config, JSON for machine-to-machine data. Know YAML's gotchas (especially automatic type coercion) when choosing for new projects.