Open in TheBrain

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


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

  1. 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.

  2. Configuration Files: Widely used in modern software development and DevOps tools (Kubernetes, Docker Compose, GitHub Actions, Ansible) to define environment setups and automated pipelines.

  3. 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

FeatureYAMLJSONXML
ReadabilityHigh (clean whitespace)Medium (brackets/quotes)Low (verbose tags)
CommentsSupported (# comment)Not natively supportedSupported (<!-- comment -->)
Primary UseConfigurations & metadataWeb APIs & data transferComplex documents & legacy schemas