YAML Ordered Mappings
YAML Ordered Mappings with !!omap
!!omap defines an ordered sequence of key:value pairs without duplicates.
For example:
ordered: !!omap
- Tom Nolan: 23
- Ryan Raynolds: 45
- Thomas Anderson: 28
Equivalent JSON
{
"ordered": [
{"Tom Nolan": 23},
{"Ryan Raynolds": 45},
{"Thomas Anderson": 28}
]
}
note
Note where the !!omap type is specified in the yaml file to preserve the order of the elements!
note
You can also use the flow style to define an ordered mapping:
ordered: !!omap [Tom Nolan: 23, Ryan Raynolds: 45, Thomas Anderson: 28]
note
The !!omap tag may be given explicitly.
Alternatively, the application may choose to implicitly type a sequence of single-key mappings to ordered maps. In this case, an explicit !seq transfer must be given to sequences of single-key mappings that do not represent ordered maps.