Basic Syntax
Special Characters
YAML supports escaping characters using backslashes:Block Modifiers
Trailing newlines are the newlines at the end of the block.
Newlines are represented as
\n in YAML.A cheatsheet for YAML basic syntax, block modifiers, and special characters.
# Key-value pairs
key: value
nested:
key: value
# Lists
items:
- item1
- item2
- item3
# YAML also supports inline JSON and lists
key: {"key": "value"}
key: [item1, item2, item3]
# Strings and numbers
integer: 42
float: 3.14
string: "42"
# Boolean values
enabled: true
disabled: false
# Null value
empty: null
key: "This is a \"string\" with a quote"
| and |-.
| preserves all trailing newlines, while |- removes all trailing newlines.Only use > when you want to convert newlines to spaces: i.e. when you want to make a long single-line string more readable.\n in YAML.# Literal Block Scalar (|): Preserves all newlines
description: |
This is a multi-line description.
Each line break is preserved exactly as written.
Indentation is respected.
# |- : Strip all trailing newlines
notes: |-
This text will have
all trailing newlines removed.
This is a multi-line description.
Each line break is preserved exactly as written.
Indentation is respected.
# Folded Block Scalar (>): Converts newlines to spaces
description: >
This is a multi-line description.
Line breaks become spaces.
Blank lines start new paragraphs.
# >- : Folded style with trailing newlines removed
description: >-
This is a long description
that spans multiple lines
but will be rendered as a single line
with trailing newlines removed.
Was this page helpful?