Skip to content

Instantly share code, notes, and snippets.

@robertchong
Last active May 6, 2026 13:06
Show Gist options
  • Select an option

  • Save robertchong/cfde3d6bbeb40b62187823777ad6fe63 to your computer and use it in GitHub Desktop.

Select an option

Save robertchong/cfde3d6bbeb40b62187823777ad6fe63 to your computer and use it in GitHub Desktop.
YAML Block Chomping Indicators: | vs |- vs |+

YAML Block Chomping Indicators: | vs |- vs |+

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.

The Three Indicators

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.

Demo

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···

Practical Notes

  • Raw base64 / certificates → use |- to avoid a trailing \n that 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

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment