YAML Scalars, Strings, and Multiline Blocks

Plain scalars, quoted strings, literal and folded blocks, and the quoting rules that prevent common YAML mistakes.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Strings and quoting
Plain string
message: Hello world

# Use an unquoted scalar when no escaping is needed.

Single-quoted string
path: 'C:\Users\jonathan
otes'

# Keep backslashes literal and avoid interpolation-like behavior.

Double-quoted string
message: "Line 1
Line 2"

# Use escapes like newline and tab in YAML strings.

Literal block scalar
body: |
  Thanks for your patience.
  Please find attached the executed agreement.

# Preserve line breaks exactly with `|`.

Folded block scalar
summary: >
  ExpressYou helps people communicate with
  more clarity, confidence, and connection.

# Wrap multi-line text into a single logical paragraph with `>`.

## Scalar gotchas
Quote ambiguous boolean-like words
answer: "yes"
feature_flag: true

# Avoid implicit booleans by quoting risky strings.

Quote date-like values
release: "2026-03-28"

# Prevent timestamps and date-like tokens from being auto-typed.

Read a scalar with yq
yq '.app.name' app.yaml

# Extract a single value from a YAML file.

Update a scalar with yq
yq -i '.app.version = "1.2.0"' app.yaml

# Modify a YAML field in place.

Recommended next

No recommendations yet.