Javatpoint Logo
Javatpoint Logo

YAML Styles

There are two types of styles in which we can write the YAML.

  • Block styles
  • Flow styles

Block Style

We previously had seen the block style. Block style is less compact and better for humans. Traditional YAML makes it easy for humans to look at the file, scan it down, and see what's going on.

Example:

In the above example, the first line shows a key-value mapping. Here, we use a colon for key-value pairs. The key is host, and the value is phl-42. The second line shows a key-value mapping indentation. It has an indentation under the datacenter. The two values under datacenter are part of datacenter mapping. They are associated with each other because they have two space indents before the actual key that is location and cab. The animal key shows a list indentation. It has indentation because it has a list under the animals. It contains the dashes to indicate that it is a list, not just a key-value.

Flow Style

Flow style is an extension of JSON. It is used to allow YAML and JSON to work together. Flow style is less human-readable, but sometimes they are better for the computer that processing our YAML. Flow style is used to fold the long line of content.

Example:

Instead of sub-line our location and cab information into indent lines under the datacenter key, we have a set of curly brackets, and we define our key: value pairs in those brackets. Similarly, we define an array into a square bracket. It also allows a different use of tag and anchors in our YAML, which we define later.


Next TopicYAML Mapping





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA