Close
Close full mode
logo.NET Thailand

YAML

Git RepositoryEdit on Github
Last update: 3 minutes ago by aaronammReading time: 2 min

How do I break a string in YAML over multiple lines?

  • Use > most of the time: interior line breaks are stripped out, although you get one at the end:
key: >
This is my very very very
long string.

Become → This is my very very very long string.\n

  • Use | if you want those line breaks to be preserved as \n (for instance, embedded markdown with paragraphs).
key: |
This is my very very very
long string.

Become → This is my very very very\nlong string.\n

  • Other options with summary table
> | " ' >- >+ |- |+
-------------------------|------|-----|-----|-----|------|------|------|------
Trailing spaces | Kept | Kept | | | | Kept | Kept | Kept | Kept
Single newline => | _ | \n | _ | _ | _ | _ | _ | \n | \n
Double newline => | \n | \n\n | \n | \n | \n | \n | \n | \n\n | \n\n
Final newline => | \n | \n | | | | | \n | | \n
Final dbl nl's => | | | | | | | Kept | | Kept
In-line newlines | No | No | No | \n | No | No | No | No | No
Spaceless newlines| No | No | No | \ | No | No | No | No | No
Single quote | ' | ' | ' | ' | '' | ' | ' | ' | '
Double quote | " | " | " | \" | " | " | " | " | "
Backslash | \ | \ | \ | \\ | \ | \ | \ | \ | \
" #", ": " | Ok | Ok | No | Ok | Ok | Ok | Ok | Ok | Ok
Can start on same | No | No | Yes | Yes | Yes | No | No | No | No
line as key
📘 Programming cookbook — Previous
WSL Issues
Next — ✔️ Testing
Enable public URL during development