In yaml, how can I create a collection of objects without naming them?
servers:
ip:
port:
login:
password:
I want something like this:
servers:
- server:
ip:
port:
login:
password:
- server:
ip:
port:
login:
password:
- server:
ip:
port:
login:
password:
An array is a group of similar values with a single name. In YAML, Array represents a single key mapped to multiple values. Each value starts with a hyphen - symbol followed by space. In a single line, write the same thing above using 'square brackets syntax.
YAML supports all essential data types, including nulls, numbers, strings, arrays, and maps.
YAML has two top-level elements, an object (which consists of key-value pairs) and an array (which consists of an ordered set of values). Keys can only be strings, while values can be one of the following types: object: a collection of key-value pairs.
YAML sequence sign (-
) is just a delimiter, so it allows to enumerate unnamed objects:
servers:
- ip:
port:
login:
password:
- ip:
port:
login:
password:
- ip:
port:
login:
password:
You may also leave -
at its own line, as it is shown in Example 2.4
in YAML spec:
servers:
-
ip:
port:
login:
password:
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