YAML
Yaml is a highly readable configuration file format. It’s closely tied with json and XML, being directly convertible to both. Much like python, yaml’s claim to fame is extreme legibility by leveraging white space as syntax. Unlike python, this is very appropriate for configuration files
Here’s a sample that covers much of yaml’s syntax:
my_key: my value
my_num: 8
my_arr: [
one:
- two
- three
Background
If yaml is so great, why isn’t it always used? The problem lies in its awful implementations
Syntax
Maps
Arrays
Multi-line Strings
Yaml has way too many ways to do multi-line strings, trying to fit every niche case. Luckily, we only really need to remember 3
One line
For a really long string that you just want on one line, use
key: >
my string starts here
and still goes on
all on the same line
Multiple lines
If you want a string over multiple lines, notable useful for formatted text, the following will preserve the visual line breaks. Indenting is determined by the indent of the first line, and white space to the left will be stripped
key: |
a yaml line starts
with line breaks preserved
Anything more complicated
Just use javascript-style multi-line strings. \ at the end will escape all the
white space until the next character. \n creates a linebreak. \" allows you
to use quotes within the string itself
key: "
my string starts here\n