YAML field notes · 02
YAML multiline strings: | vs > and the chomping indicators, tested side by side
| (literal) keeps every line break; > (folded) turns single line breaks into spaces. The character after it controls the end: - removes the final newline, + keeps it and any blank lines after it, and with neither you get exactly one final newline. The table shows the exact JSON string each of the six forms produced in our converter.
The six forms, same text
Each key below holds the same two lines, followed by one blank line. We converted the file to JSON, where every newline shows up as \n:
literal: |
Line one
Line two
literal_strip: |-
Line one
Line two
literal_keep: |+
Line one
Line two
folded: >
Line one
Line two
folded_strip: >-
Line one
Line two
folded_keep: >+
Line one
Line two
last: end
| Header | JSON string | What it does |
|---|---|---|
literal: | | "Line one\nLine two\n" | Keeps line breaks; one final newline |
literal_strip: |- | "Line one\nLine two" | Keeps line breaks; no final newline |
literal_keep: |+ | "Line one\nLine two\n\n" | Keeps line breaks and every trailing blank line |
folded: > | "Line one Line two\n" | Joins lines with spaces; one final newline |
folded_strip: >- | "Line one Line two" | Joins lines with spaces; no final newline |
folded_keep: >+ | "Line one Line two\n\n" | Joins lines; keeps every trailing blank line |

+ forms keep the blank line, as a second \n.Open this example in the converter →
The YAML 1.2.2 specification names the three endings strip (-), clip (the default) and keep (+) in its section on the block chomping indicator. Clip is why a plain | gives exactly one \n no matter how many blank lines follow it.
What folding actually joins
> does not turn every newline into a space. A blank line becomes a line break, and lines indented further than the first line are kept as they are, with their breaks (folded style):
folded: >
First paragraph
continues here.
Second paragraph.
An indented line
stays as is.
Back to folding.{
"folded": "First paragraph continues here.\nSecond paragraph.\n An indented line\n stays as is.\nBack to folding.\n"
}So > suits prose that you want to wrap in the editor, and | suits anything where each line means something: scripts, certificates, config fragments.
Two other ways to write long text also span lines. A plain (unquoted) value continued on the next lines is folded too (single breaks become spaces and blank lines become line breaks, but more-indented lines are not kept as they are), and a double-quoted value can use \n escapes:
plain: This is
one long
plain scalar
quoted: "line one\n
line two"{
"plain": "This is one long plain scalar",
"quoted": "line one\n line two"
}Note the space before line two: in a double-quoted string the line break after \n is still folded into a space.
When the text starts with spaces
A block’s indentation is taken from its first non-empty line. If that line of your text itself starts with spaces, the parser cannot tell indentation from content, and the next, less indented line breaks the file:
bad: |
starts with four
then twoLine 3, column 1: All mapping items must start at the same columnAn indentation indicator fixes it: |2 says the content is indented two spaces more than the line with the key, so anything beyond that is text (block indentation indicator):
indented: |2
starts with two spaces
then none{
"indented": " starts with two spaces\nthen none\n"
}In CI and Kubernetes files
GitHub’s workflow reference shows multi-line commands written with |, and says that each line runs in the same shell. Write the same step with > and the lines are folded first, so the shell gets a single command line:
steps:
- name: Build
run: |
npm ci
npm run build
- name: Build (wrong indicator)
run: >
npm ci
npm run build
- name: One long command
run: >
docker build
--tag app:latest
--file Dockerfile .

| the run value is "npm ci\nnpm run build\n"; with > it is "npm ci npm run build\n", one command with extra words.Open this example in the converter →
The third step is where > is the right choice: one long command split over lines for readability becomes "docker build --tag app:latest --file Dockerfile .\n".
Kubernetes ConfigMaps use | the same way to hold whole files, as in the ConfigMap documentation’s game.properties key: open it in the converter to see the file as one JSON string.
Sources
- YAML 1.2.2 specification, 8.1.1 and 8.1.3: chomping (strip, clip, keep), indentation indicator, folded style
- GitHub Docs, Workflow syntax: jobs.<job_id>.steps[*].run: multi-line commands with |
- Kubernetes documentation, ConfigMaps: file-like keys written with |
All pages were read on 10 November 2026. Converter outputs on this page are generated by the same code that runs in the converter.