YAML Document Structures- YAML tutorial - YAML Example



YAML uses three dashes (“—”) to separate directives from document content. This also serves to signal the start of a document if no directives are present. Three dots ( “…”) indicate the end of a document without starting a new one, for use in communication channels.

1. Two Documents in a Stream (each with a leading comment)

# Ranking of 1998 home runs---- Mark McGwire- Sammy Sosa- Ken Griffey# Team ranking---- Chicago Cubs- St Louis Cardinals

2. Play by Play Feed from a game

---time: 20:03:20player: Sammy Sosaaction: strike (miss)...---time: 20:03:47player: Sammy Sosaaction: grand slam...

3. Single Document with Two Comments

---hr: # 1998 hr ranking  - Mark McGwire  - Sammy Sosarbi:  # 1998 rbi ranking  - Sammy Sosa  - Ken Griffey

Repeated nodes (objects) are first identified by an anchor (marked with the ampersand -“&) and are then aliased (referenced with an asterisk – *) thereafter.

4. Node for “Sammy Sosa” appears twice in this document

---hr:  - Mark McGwire  # Following node labeled SS  - &SS Sammy Sosarbi:  - *SS # Subsequent occurrence  - Ken Griffey

5. Compact Nested Mapping

---# Products purchased- item    : Super Hoop  quantity: 1- item    : Basketball  quantity: 4- item    : Big Shoes  quantity: 1

Complex Mapping:

---? - key:  - value# Note: key and value can be multiple, complex structures

6. Mapping between Sequences

? - Detroit Tigers  - Chicago cubs:  - 2001-07-23? [ New York Yankees,    Atlanta Braves ]: [ 2001-07-02, 2001-08-12,    2001-08-14 ]

Corresponding JSON

{"[\"Detroit Tigers\", \"Chicago cubs\"]": ["2001-07-23"],"[\"New York Yankees\", \"Atlanta Braves\"]": [   "2001-07-02",   "2001-08-12",   "2001-08-14" ]}