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

How plain, single-quoted, and double-quoted strings behave in YAML.

Plain string

Use an unquoted scalar when no escaping is needed.

yamlANYyamlstringplain
yaml
message: Hello world

Plain scalars are concise, but they can be misread when values look like booleans, dates, or special tokens.

Single-quoted string

Keep backslashes literal and avoid interpolation-like behavior.

yamlANYyamlstringsingle-quotes
yaml
path: 'C:\Users\jonathan
otes'

Single quotes reduce escaping needs. To include a single quote, double it.

Double-quoted string

Use escapes like newline and tab in YAML strings.

yamlANYyamlstringdouble-quotesescapes
yaml
message: "Line 1
Line 2"

Double quotes support common escape sequences and are useful for values needing explicit escaping.

Literal block scalar

Preserve line breaks exactly with `|`.

yamlANYyamlmultilineliteral-block
yaml
body: |
  Thanks for your patience.
  Please find attached the executed agreement.

Literal blocks preserve newlines and are ideal for emails, certificates, Markdown, or shell scripts.

Folded block scalar

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

yamlANYyamlmultilinefolded-block
yaml
summary: >
  ExpressYou helps people communicate with
  more clarity, confidence, and connection.

Folded blocks convert line breaks into spaces, which is useful for longer prose values.

Scalar gotchas

Examples that prevent hard-to-debug YAML parsing surprises.

Quote ambiguous boolean-like words

Avoid implicit booleans by quoting risky strings.

yamlANYyamlbooleansquoting
yaml
answer: "yes"
feature_flag: true

In some parsers or older YAML variants, words like yes/no/on/off may be interpreted as booleans.

Quote date-like values

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

yamlANYyamldatesquoting
yaml
release: "2026-03-28"

Quote values when you need them treated as strings instead of dates or timestamps.

Read a scalar with yq

Extract a single value from a YAML file.

bashANYyamlyqquery
bash
yq '.app.name' app.yaml

Useful in scripts and CI jobs that need one config value.

Update a scalar with yq

Modify a YAML field in place.

bashANYyamlyqedit
bash
yq -i '.app.version = "1.2.0"' app.yaml

A convenient way to bump versions or toggle config values automatically.

Recommended next

No recommendations yet.