YAML tricks

(, en)

YAML is a tricky format and can lead to surprises. Best example: The yaml document from hell

Multiline Blocks

#    ┌── bock style
#    │┌─ block chomping
#    ││
key: |-
  Lorem ipsum dolor sit amet,
  consectetur adipiscing elit,
  sed do eiusmod tempor incididunt
  ut labore et dolore magna aliqua.

\N non-space character

\n newline

| keep as is (literal)
> replace \N\n\N with \N \N (folded)
(nothing) single \n at the end (clip)
- no newline at the end (strip)
+ keep everything (keep)

Formatting YAML

<file.yaml yq '. style="literal"'


See also