6 min read
JSON vs YAML: Differences and When to Use Each
Compare JSON and YAML syntax, strictness, and tooling, and learn which format fits APIs, configuration, and CI pipelines.
The short answer
Use JSON for data exchanged between programs, especially APIs. Use YAML for configuration that humans edit by hand, such as Kubernetes manifests, GitHub Actions workflows, and Docker Compose files.
Same data, two syntaxes
YAML 1.2 is a superset of JSON, so the same structure can be written either way. JSON relies on braces, brackets, and quotes; YAML relies on indentation.
{"service":"api","replicas":2,"ports":[80,443]}
service: api
replicas: 2
ports:
- 80
- 443Where YAML surprises people
Indentation is meaningful and tabs are not allowed. Unquoted values are typed automatically, so older YAML 1.1 parsers read no, off, and yes as booleans and a value like 1.10 as the number 1.1. Quote strings when their type matters.
YAML also supports comments, anchors, and multi-line strings, which JSON does not. These features make configuration nicer to write but harder to parse safely, so avoid loading untrusted YAML with permissive loaders.
Converting between them
Converting JSON to YAML is always possible. Converting YAML to JSON loses comments and expands anchors into repeated values. DevKitly's converters work in both directions and report the line where parsing failed.
