The | symbol denotes a literal block scalar — newlines inside the value are preserved as-is.
The character after it is the block chomping indicator, controlling how trailing newlines are handled.
| Indicator | Name | Trailing newline |
|---|---|---|
| |
Clip (default) | Keeps one trailing newline |
|- |
Strip | Removes all trailing newlines |
|+ |
Keep | Preserves all trailing newlines |
Internal newlines (between lines of content) are always preserved — chomping only affects trailing newlines after the last line.
clip: |
hello
world
strip: |-
hello
world
keep: |+
hello
world
import yaml
data = yaml.safe_load("""
clip: |
hello
world
strip: |-
hello
world
keep: |+
hello
world
""")
for key, value in data.items():
print(f"{key!r}: {value!r}")
Output:
'clip': 'hello\nworld\n'
'strip': 'hello\nworld'
'keep': 'hello\nworld\n\n\n'
Visualized with · representing a newline:
| Indicator | Value |
|---|---|
| clip |
hello·world· |
|- strip |
hello·world |
|+ keep |
hello·world··· |
- Raw base64 / certificates → use
|-to avoid a trailing\nthat can break strict decoders - PEM certificates (with
-----BEGIN/END-----headers) →|is fine; most PEM parsers are lenient - Kubernetes secrets/manifests, Helm charts →
|-is the safe default for any cert or key material