YAML Basics

Core YAML syntax, indentation rules, maps, lists, and practical validation commands for day-one and day-100 YAML workflows.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Scalars, maps, and sequences
Simple mapping
name: ExpressYou
plan: premium
active: true

# Define key-value pairs in YAML.

Simple sequence
features:
  - message generator
  - fix this message
  - screenshot to reply

# Represent ordered lists with dashes.

Nested mapping and list
app:
  name: ExpressYou
  pricing:
    monthly: 7.99
    yearly: 59.99
  tools:
    - coach me
    - message generator

# Combine objects and arrays in one document.

Nulls, booleans, and numbers
draft: null
enabled: true
max_retries: 3
price: 7.99

# Show common scalar values.

## Validate and inspect YAML from the terminal
Lint a YAML file
yamllint config.yaml

# Check a file for syntax and style problems.

Parse YAML with Python
python - <<'PY'
import yaml
with open('config.yaml') as f:
    print(yaml.safe_load(f))
PY

# Quickly verify that a YAML file loads successfully.

Pretty-print YAML with yq
yq '.' config.yaml

# Read and normalize YAML output from the command line.

Validate Kubernetes YAML client-side
kubectl apply --dry-run=client -f deployment.yaml

# Check whether a manifest parses before applying it.

Recommended next

No recommendations yet.