Skip to content

YAML Sequence Style

Learn how YAML sequences use block and flow styles to represent ordered collections of items with examples and JSON output comparisons.

YAML Sequence Style

YAML Sequences Styles are closely related to the concept of collections.

The collection in YAML is represented with proper sequence styles.

Example

The following code shows how to represent a sequence style, comparing block style and flow style:

Block style: !!seq
- Mercury   # Comment.
- Venus     # Comment.
- Earth     # Comment.
- Mars      # Comment.
- Jupiter   # Comment.
- Saturn    # Comment.
- Uranus    # Comment.
- Neptune   # Comment.
- Pluto     # Comment?
Flow style: !!seq [ Mercury, Venus, Earth, Mars,      # Comment
                    Jupiter, Saturn, Uranus, Neptune, # Comment
                    Pluto ]                           # Comment

The JSON output of the given YAML is as follows:

{
	"Flow style": [
		"Mercury",
		"Venus",
		"Earth",
		"Mars",
		"Jupiter",
		"Saturn",
		"Uranus",
		"Neptune",
		"Pluto"
	],

	"Block style": [
		"Mercury",
		"Venus",
		"Earth",
		"Mars",
		"Jupiter",
		"Saturn",
		"Uranus",
		"Neptune",
		"Pluto"
	]
}
Navigation