Cheatsheets - YAML
Last Updated: 2023-08-27
Multiline Strings
Indented text that follows should be interpreted as a multi-line scalar value
- default: newlines become spaces.
|
: preserves newlines.|+
: keep extra newlines after the block.|-
: remove extra newlines after block.
>
: newlines are converted to spaces.>+
: keep extra newlines after the block.>-
: remove extra newlines after block.
$ cat <<EOF | yq '.content'
content:
a b
c d e
f g
EOF
# a b c d e
# f g
$ cat <<EOF | yq '.content'
content: |
a b
c d e
f g
EOF
# a b
# c d e
#
# f g
#
$ cat <<EOF | yq '.content'
content: |+
a b
c d e
f g
EOF
# a b
# c d e
#
# f g
#
$ cat <<EOF | yq '.content'
content: |-
a b
c d e
f g
EOF
# a b
# c d e
#
# f g
$ cat <<EOF | yq '.content'
content: >
a b
c d e
f g
EOF
# a b c d e
# f g
#
$ cat <<EOF | yq '.content'
content: >-
a b
c d e
f g
EOF
# a b c d e
# f g
Interactive examples: https://yaml-multiline.info/
Single-quoted vs Double-quoted
- single: don't escape (e.g.
\n
,\"
has no effects). To escape single quotes:''
. - double: escapes work. To escape double quotes:
\"
.