YAML Front-Matter
YAML (which stands recursively for YAML Ain't Markup Language) is a human-readable data serialization format. It is most commonly used for configuration files, data storage, and sharing structured data between applications written in different programming languages.
Key Characteristics
- Human-Readable & Minimal: Designed to be clean and readable without the clutter of excessive tags, brackets, or braces.
- Indentation-Based Structure: Like Python, YAML uses white space and indentation (strictly spaces, not tabs) to denote hierarchy and structure.
- Superset of JSON: Any valid JSON file is technically valid YAML, making it easy to convert between the two formats.
Basic Syntax & Examples
1. Key-Value Pairs
Simple scalars are written as basic key-value pairs.
name: San Juan Capistrano
founded: 1776
is_active: true
2. Lists / Sequences
Items in a sequence or list begin with a hyphen - followed by a space.
teams:
- Angels
- Dodgers
- Padres
3. Nested Maps / Objects
Structures can be nested using indentation.
player:
name: Mike Trout
position: Outfield
stats:
home_runs: 370
batting_average: 0.299
4. Inline / Compact Syntax
You can also write arrays and objects using JSON-like syntax when brevity is preferred.
aliases: [AI, Machine Learning, Deep Learning]
settings: { theme: dark, auto_save: true }
5. Multi-line Strings
YAML easily handles long, multi-line blocks of text using literal | (preserves line breaks) or folded > (folds line breaks into spaces) operators.
description: |
Line 1 of text.
Line 2 of text.
Common Uses
- Front-Matter Metadata: Placed at the top of Markdown files (between
---delimiters) in static site generators (Hugo, Jekyll) and PKM tools (TheBrain, Obsidian) to store metadata like tags, dates, and aliases. - Configuration Files: Widely used in modern software development and DevOps tools (Kubernetes, Docker Compose, GitHub Actions, Ansible) to define environment setups and automated pipelines.
- Data Exchange: Used across software APIs and language implementations where humans need to inspect or edit the underlying configuration directly.
Quick Comparison: YAML vs. JSON vs. XML
| Feature | YAML | JSON | XML |
|---|---|---|---|
| Readability | High (clean whitespace) | Medium (brackets/quotes) | Low (verbose tags) |
| Comments | Supported (# comment) | Not natively supported | Supported (<!-- comment -->) |
| Primary Use | Configurations & metadata | Web APIs & data transfer | Complex documents & legacy schemas |