# YAML Basics **YAML** (YAML Ain’t Markup Language) is a human-readable data serialization format. It's used to represent data structures like dictionaries, lists, and scalars — making it ideal for configuration files, especially in DevOps and content workflows. --- ## Why Use YAML? - 🧠 **Readable**: Easy to scan and write by hand. - ⚡ **Clean Syntax**: No curly braces, brackets, or commas. - 🛠️ **Widely Used**: Found in tools like Ansible, Kubernetes, GitHub Actions, Hugo/SSG frontmatter, etc. - 🔄 **Cross-compatible**: Can often be converted to/from JSON. - ✍️ **Easier to write than JSON**, especially for complex nested structures. - 👁️ **JSON is often easier to read programmatically**, making it a better fit for APIs and data transmission. --- ## Basic Syntax Rules ### Scalars ```yaml title: YAML Basics published: true views: 420 ``` ### Lists ```yaml features: - human-friendly - clean syntax - supports nesting ``` ### Dictionaries (Maps) ```yaml author: name: Jack Beesley role: Security Architect ``` ### Nested Structures ```yaml post: title: YAML Basics tags: - devops - automation metadata: views: 420 featured: true ``` --- ## Best Practices - Use **two spaces** for indentation (never tabs). - Strings with special characters can be quoted (`"` or `'`). - Use consistent casing for keys (e.g. `snake_case`, `camelCase`). - Validate YAML with online tools or linters. --- ## Where You'll See YAML - Frontmatter in Markdown files (e.g., for SSGs like Hugo, Jekyll) - GitHub Actions workflows - Kubernetes manifests - Ansible playbooks - Docker Compose files - CI/CD pipelines --- ## References - Official YAML website: [yaml.org](https://yaml.org/) - YAML Specification: [https://yaml.org/spec/](https://yaml.org/spec/) - JSON vs YAML comparison: [https://www.json2yaml.com/](https://www.json2yaml.com/) - Online YAML validator: [https://codebeautify.org/yaml-validator](https://codebeautify.org/yaml-validator) ## Summary YAML is a lightweight, readable way to structure data for humans. It’s everywhere in infrastructure-as-code and content pipelines. Use it when you want something easy to type, skim, and manage. If you’re working with web automation, deployment, or structured metadata — YAML is your friend.