Search code examples
arraysyaml

How do I create an empty array in YAML?


array_with_three_elements:
- 1
- 2
- 3

empty_array:

Is there any way to specify that empty_array: is an array with no elements, such as with []? When I load it into a ruby hash I'd like it to know that it's an array.


Solution

  • Try using [], like:

    empty_array: []
    

    So in Ruby you have:

    x = YAML::load("empty_array: []")
    x # => {"empty_array" => []}