Skip to main content
YAML

YAML

Active

YAML Ain't Markup Language is a human-readable data serialization format designed for configuration files and data exchange. YAML 1.2.2 (2021) is a strict superset of JSON. It is the primary configuration language for Kubernetes, GitHub Actions, Docker Compose, Ansible, and most modern DevOps tooling.

Data Formatyaml.org 1.2.2ConfigKubernetesDevOps2001
Types

In one line

YAML (YAML Ain't Markup Language) is defined by the yaml.org 1.2.2 spec (2021). It is a strict superset of JSON – every valid JSON document is valid YAML. YAML adds block style (indentation-based), comments, multi-line strings, anchors/aliases for deduplication, and type tags. It is the dominant format for Kubernetes manifests, GitHub Actions workflows, and Docker Compose files.

Quick Reference

FieldSizeDescription
Superset of JSONYesEvery valid JSON document is valid YAML 1.2. Parsers that target 1.1 may diverge on true/false vs yes/no.
IndentationSpaces onlyBlock style uses 2-space indentation by convention. Tabs are forbidden as indentation characters.
Comments# syntaxComments begin with # and run to end of line. JSON has no comment syntax – this is YAML's most-used addition.
Scalars6 typesStrings, integers, floats, booleans (true/false only in 1.2), null, timestamps. Type inferred from value pattern.
Block sequences- itemArrays written as dash-prefixed items. Flow sequences use JSON array syntax [a, b, c].
Block mappingskey: valueMaps written as key: value pairs. Flow mappings use JSON object syntax {a: 1, b: 2}.
Anchors/Aliases&anchor *ref& defines an anchor, * references it. Enables DRY configuration. Merge key << merges an anchored map.
Multi-line strings| and >Literal block scalar (|) preserves newlines. Folded block scalar (>) folds newlines to spaces.
Type tags!!typeExplicit type: !!str "123" forces string. !!int, !!float, !!bool, !!null, !!timestamp available.

Key Characteristics

Human-readable

Indentation-based structure is highly readable. Comments explain configuration intent. Dominant in DevOps tooling for this reason.

The Norway Problem

YAML 1.1 parsed country codes NO, FI, etc. as booleans. YAML 1.2 fixed this – true/false only. Legacy parsers (PyYAML < 6.0) still use 1.1 behavior.

Anchors and aliases

& and * enable DRY config. A single anchored map can be merged into many resources via <<: *anchor. Reduces repetition in large manifests.

Kubernetes native

All Kubernetes manifests are YAML. kubectl apply -f reads YAML. Helm charts are YAML templates. GitHub Actions workflows are YAML.

Message Format

Request
http
# Kubernetes Deployment – block style YAML
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
  labels:
    app: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    spec:
      containers:
        - name: my-app
          image: my-app:1.0.0
          ports:
            - containerPort: 8080
Response
http
# Anchors and aliases – DRY configuration
x-defaults: &defaults
  restartPolicy: Always
  imagePullPolicy: IfNotPresent

containers:
  - name: app
    <<: *defaults        # merge defaults
    image: app:1.0

# Multi-line string styles
literal: |
  Line one
  Line two
  Line three

folded: >
  This long sentence
  folds into one line.

# Explicit type tags
port:  !!int  "8080"     # string "8080" coerced to int
token: !!str  true       # boolean true coerced to string

Implementations

linuxsince PyYAML (Python), go-yaml (Go), js-yaml (Node.js), snakeyaml (Java), serde-yaml (Rust)available
macossince Same as Linux; yq CLI via Homebrew for jq-style YAML queryingavailable
windowssince PyYAML, YamlDotNet (.NET), js-yamlavailable
iossince Yams (Swift), YAMLKitavailable
androidsince snakeyaml (Java/Kotlin)available