YAML and JSON Configuration Formats
What are YAML and JSON? When would you use each format in DevOps?
YAML (YAML Ain't Markup Language) and JSON (JavaScript Object Notation) are data serialization formats. YAML is human-readable with indentation-based syntax, supports comments, and is preferred for configuration files (Kubernetes, Ansible, CI/CD). JSON is more compact, has strict syntax, and is preferred for APIs and machine-to-machine communication. Both represent the same data structures: objects/maps, arrays/lists, and scalar values.
DevOps engineers work with YAML and JSON daily. Kubernetes manifests, Helm charts, GitHub Actions, and Ansible playbooks all use YAML. APIs typically return JSON. Understanding both formats and being able to convert between them is essential. Common pitfalls include YAML indentation errors and JSON trailing commas.
YAML example
Equivalent JSON
- Using tabs instead of spaces in YAML (only spaces allowed)
- Inconsistent indentation in YAML files
- Trailing commas in JSON arrays/objects (not allowed)
- Forgetting to quote strings with special characters in YAML
- What common YAML mistakes cause parsing errors?
- How do you validate YAML or JSON files?
- What tools can convert between YAML and JSON?