YAML Multiline Strings Explained
Long text values — a script, a description, an email template — are one of the places YAML is genuinely more pleasant to write than JSON, once you know the two symbols involved.
The literal block scalar: |
description: |
This service handles user authentication.
It exposes a REST API on port 8080.
Restart it after changing the config.
The pipe | means "keep every line break exactly as written." The value of description becomes a string with three actual newline characters in it — useful for scripts, code snippets, or anything where line breaks are meaningful.
The folded block scalar: >
summary: >
This service handles user authentication
and exposes a REST API on port 8080.
Restart it after changing the config.
The > folds line breaks into spaces instead, turning those three lines into one long sentence with no line breaks at all (a blank line in the source becomes an actual line break in the output, if you need an occasional paragraph split). This is the one to reach for when you're writing a paragraph that just happens to be wrapped across several lines in your editor, but should read as continuous text.
Controlling the trailing newline
By default, both styles keep a single trailing newline at the end of the string and strip any extra blank lines. You can change that with a modifier right after the symbol:
|-or>-— strip the trailing newline entirely.|+or>+— keep all trailing blank lines exactly as written.
A quick way to check you got it right
Because the difference between | and > is invisible until you actually look at the parsed string, the fastest way to confirm your multiline value came out the way you expected is to convert your YAML to JSON with our converter — JSON's escaped \n characters will make it immediately obvious whether your line breaks survived or got folded away.