How can I define a multi-line array in YAML?

I want to define a YAML array across multiple lines for readability, something like breaking long inline arrays into multiple lines.

I know YAML supports sequences using dashes or brackets, but is there a clean way to define a yaml array over multiple lines without resorting to string hacks or post-processing in code?

Honestly, the easiest and cleanest way is the dash (-) syntax:

yaml
Copy
Edit
my_list:
  - item1
  - item2
  - item3

It’s super readable and the most YAML-native way to do multi-line arrays.

I use this for config files all the time, it avoids any parsing weirdness.

If you really want to keep the bracket syntax but break it across lines, YAML allows that too, just be mindful of indentation:

yaml
Copy
Edit
my_list: [
  item1,
  item2,
  item3
]

I use this when the array is short and part of a nested object.

It still parses correctly, but I only use it when I want to keep the value visually inline with the key.

@arpanaarora.934 At first, I thought the | syntax would let me create multi-line arrays like this:

yaml
Copy
Edit
my_list: |
  - item1
  - item2

But turns out that just creates a string, not an actual array.

If you parse it, it’s a single string with dashes in it.

So yeah, definitely stick with the dash syntax or bracketed lists if you want actual array structures.