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
| style | |
|---|---|
| |
keep as is (literal) |
> |
replace \N\n\N with \N \N (folded) |
| chomping | |
|---|---|
| (nothing) | single \n at the end (clip) |
- |
no newline at the end (strip) |
+ |
keep everything (keep) |
Formatting YAML
<file.yaml yq '. style="literal"'
Alternatives
- Jsonnet - The Data Templating Language: I used it before and I really like it. It takes away the pain points of JSON, is more powerful than YAML and does not suffer from all the quirks YAML has.
- CUE: I did not try it, but it seems to be interesting. Only the documentation is not really good.
