YAML Cheat Sheet
YAML cheatsheet for YAML syntax and structures, including mappings, sequences, scalars, indentation rules, block and flow styles, block scalar (| and >) forms, anchors and aliases, merge keys, tags, and multi-document YAML streams.
Comment
A comment starts with # and continues to the end of the line.
# comment
key: value # inline comment
# metadata
title: example # stored as a plain scalar
Document Start and End
Document start is --- and document end is ... in a YAML stream.
---
key: value
...
---
apiVersion: v1
kind: ConfigMap
...
Mapping
A mapping is a set of key/value pairs; keys are typically plain scalars and values can be any YAML node.
key: value
key2: 123
nested:
child: value
service:
name: web
port: 8080
tls:
enabled: true
Sequence
A sequence is an ordered list of items using - indicators.
- item1
- item2
- key: value
hobbies:
- hiking
- coding
- movies
Flow Sequence
A flow sequence uses bracket notation and comma-separated items.
[ item1, item2, item3 ]
movies: [ "Dark Knight", "Good Will Hunting" ]
Flow Mapping
A flow mapping uses brace notation and comma-separated key/value pairs.
{ key1: value1, key2: value2 }
friend: { name: "Adam", age: 22 }
Indentation
Indentation defines structure; nested nodes are indented consistently under their parent.
parent:
child: value
list:
- a
- b
person:
name: daniel
friends:
- name: steph
age: 22
Plain Scalar
A plain scalar is an unquoted value; interpretation depends on schema/resolution.
key: plain value
key2: unquoted-string
env: production
region: us-east-1
Single-Quoted Scalar
Single quotes preserve content literally; the only escape is doubling a single quote.
key: 'literal text'
key2: 'it''s escaped by doubling'
path: 'C:\Users\name\templates'
note: 'don''t expand \n here'
Double-Quoted Scalar
Double quotes support escape sequences such as \n, \t, and \uXXXX.
key: "text"
escaped: "Line1\nLine2"
unicode: "pi: \u03C0"
message: "tab\tseparated"
file: "C:\\tmp\\file.txt"
Multiline Literal Block Scalar (|)
The literal block scalar preserves newlines and indentation as part of the value.
key: |
line1
line2
signature: |
Aiman
PHHM Organization
email - hejes@gmail.com
Multiline Folded Block Scalar (>)
The folded block scalar folds most newlines into spaces while keeping paragraph breaks.
key: >
line1
line2
description: >
Labore officia laborum Lorem culpa excepteur anim et.
Eiusmod non quis qui tempor ea proident consectetur eiusmod
ipsum.
Block Scalar Chomping Indicators
Chomping indicators control trailing line breaks: |- strips, | clips, |+ keeps (same for >).
clip: |
text
strip: |-
text
keep: |+
text
banner_clip: |
hello
banner_strip: |-
hello
banner_keep: |+
hello
Null
A null represents an explicit null value; null and ~ are commonly used.
key1: null
key2: ~
flaws: null
middle_name: ~
Boolean
Booleans are true and false (YAML 1.2 core schema).
enabled: true
disabled: false
feature_flag: true
maintenance_mode: false
Integer
Integers are whole numbers.
count: 3
negative: -21
replicas: 5
port: 8080
Float
Floats use a decimal point and/or exponent notation.
pi: 3.1415
small: 1e-6
gpa: 3.5
fav_num: 1e+10
Timestamp
Date/time scalars may be resolved as timestamps by some processors/schemas.
birthday: 2001-01-23 10:00:00
released_at: 2025-12-25 09:30:00
Explicit Tag
Tags can explicitly identify a node’s type using !!<type>.
age: !!float 18
gpa: !!str 3.5
threshold: !!float 0.75
version: !!str 1.0
Anchor (&) and Alias (*)
An anchor assigns a reusable node; an alias references the anchored node.
name: &name "daniel"
id: *name
defaults: &defaults
retries: 3
timeout_ms: 5000
service_a:
config: *defaults
Merge Key (<<)
The merge key inserts key/value pairs from one or more mappings into the current mapping.
base: &base
var1: value1
foo:
<<: *base
var2: value2
defaults: &defaults
host: localhost
port: 5432
prod:
<<: *defaults
host: db.example
Merge Key with Multiple Sources
A merge value can be a sequence of mappings; merges are applied in order.
base1: &base1
a: 1
b: 1
base2: &base2
b: 2
c: 2
target:
<<: [*base1, *base2]
c: 99
common: &common
log_level: info
retries: 3
region: ®ion
region: eu-west-1
retries: 5
service:
<<: [*common, *region]
name: api
Sequence of Mappings
A sequence can contain mappings, including flow-style mappings inside a sequence.
friends:
- name: steph
age: 22
- {name: Adam, age: 22}
nodes:
- id: n1
role: leader
- { id: n2, role: worker }
Mapping Value as Sequence
A mapping key can map to a sequence value.
key:
- a
- b
ports:
- 80
- 443
Multi-Document Stream
A YAML stream may contain multiple documents separated by ---.
---
kind: A
spec: {}
---
kind: B
spec: {}
---
env: dev
---
env: prod