Should the following be valid?
parent:
- child
- child
So what we have is a sequence of values inside a mapping.
The specific question is about whether the indentation for the 2nd and 3rd lines is valid. The Ruby YAML.dump generated this code, but the Yaml parser here rejects it, because the child lines are not indented.
i.e. it wants something like:
parent:
- child
- child
Who is right?
Looking at the YAML spec, it's certainly not obvious, and the line
The “-”, “?” and “:” characters used to denote block collection entries are perceived by people to be part of the indentation
doesn't help much.
The valid YAML indentation is shown below − a: b: - c - d - e f: "ghi" You should remember the following rules while working with indentation in YAML:Flow blocks must be intended with at least some spaces with surrounding current block level. Flow content of YAML spans multiple lines.
Sequences can also be known as lists, arrays. Along with mapping, YAML can also be considered as a collection. In YAML, the collection is represented with proper sequence styles. The first example shows the collection. It contains a list under roles. The datacenter mapping, location, cab, and cab_unit are also a collection.
In this file, we actually write a pretty typical YAML file using just two basic YAML features: mapping, sequences, and combination of mapping and sequences.
# Ordered sequence of nodes in YAML STRUCTURE Block style: !!seq - Mercury # Rotates - no light/dark sides. - Venus # Deadliest.
Yes, that is legal YAML. The relevant text from the spec is here:
Since people perceive the “-” indicator as indentation, nested block sequences may be indented by one less space to compensate, except, of course, if nested inside another block sequence (block-out context vs. block-in context).
and the subsequent example 8.22:
sequence: !!seq
- entry
- !!seq
- nested
mapping: !!map
foo: bar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With