YAML vs JSON — which one for configuration?
YAML favours human editing with comments and fewer braces; JSON is unambiguous and machine-friendly. Configure with YAML, transport with JSON.
Quick verdict
- Human-edited configuration → YAML.
- Program-to-program data and APIs → JSON.
- Config management (Kubernetes, GitHub Actions) → YAML dominates.
Side-by-side
| Property | YAML | JSON |
|---|---|---|
| Comments | # lines |
Not supported (JSONC is the workaround) |
| Readability | High | Moderate |
| Ambiguity | Some, especially YAML 1.1 (yes / no) |
Very low |
| Anchors / references | Yes | No |
| Parser strictness | Implementation-dependent | Strict |
Operational tips
- Use
yaml.safe_load—yaml.loadcan instantiate arbitrary objects, an RCE-class bug. - JSON forbids trailing commas; rely on
jqor Prettier to keep formatting consistent. - CI config wins for YAML, gRPC and OpenAPI runtime exchanges win for JSON.