Is there any difference if i use one space, two or four spaces per indent level in YAML?
Are there any specific rules for space numbers per Structure type??
For example 4 spaces for nesting maps , 1 space per list item etc??
I am writing a yaml configuration file for elastic beanstalk .ebextensions and i am having really hard time constructing this correctly. Although i have valid yaml in YAML Validator elastic beanstalk seems to understand a different structure.
An indent has one space between the first character of the indent and the first character of each subsequent indent, while a tab has two spaces between each tab. Paragraphs have three spaces between each paragraphs.
Spaces are allowed in keys according to the specification and for those you don't need quotes (double or single, each with their own use). It is just a scalar string containing a space.
In YAML block styles, structure is determined by indentation. In general, indentation is defined as a zero or more space characters at the start of a line. To maintain portability, tab characters must not be used in indentation, since different systems treat tabs differently.
A YAML file use spaces as indentation, you can use 2 or 4 spaces for indentation, but no tab. In other words, tab indentation is forbidden: Why does YAML forbid tabs? Tabs have been outlawed since they are treated differently by different editors and tools.
There is no requirement in YAML to indent any concrete number of spaces. There is also no requirement to be consistent. So for example, this is valid YAML:
a: b: - c - d - e f: "ghi"
Some rules might be of interest:
{
or [
) can span multiple lines, but must be indented at least as many spaces as the surrounding current block level.-
is considered part of the indentation:a: # top-level key - b # value of that key, which is a list - c c: # next top-level key d # non-list value which must be more indented
The YAML spec for v 1.2 merely says that
In YAML block styles, structure is determined by indentation. In general, indentation is defined as a zero or more space characters at the start of a line.
To maintain portability, tab characters must not be used in indentation, since different systems treat tabs differently. Note that most modern editors may be configured so that pressing the tab key results in the insertion of an appropriate number of spaces.
The amount of indentation is a presentation detail and must not be used to convey content information.
So you can set the indent depth to your preference, as long as you use spaces and not tabs. Interestingly, IntelliJ uses 2 spaces by default.
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