| 1 | |
|---|
| 2 | # |
|---|
| 3 | # Examples from the Preview section of the YAML specification |
|---|
| 4 | # (http://yaml.org/spec/1.2/#Preview) |
|---|
| 5 | # |
|---|
| 6 | |
|---|
| 7 | # Sequence of scalars |
|---|
| 8 | --- |
|---|
| 9 | - Mark McGwire |
|---|
| 10 | - Sammy Sosa |
|---|
| 11 | - Ken Griffey |
|---|
| 12 | |
|---|
| 13 | # Mapping scalars to scalars |
|---|
| 14 | --- |
|---|
| 15 | hr: 65 # Home runs |
|---|
| 16 | avg: 0.278 # Batting average |
|---|
| 17 | rbi: 147 # Runs Batted In |
|---|
| 18 | |
|---|
| 19 | # Mapping scalars to sequences |
|---|
| 20 | --- |
|---|
| 21 | american: |
|---|
| 22 | - Boston Red Sox |
|---|
| 23 | - Detroit Tigers |
|---|
| 24 | - New York Yankees |
|---|
| 25 | national: |
|---|
| 26 | - New York Mets |
|---|
| 27 | - Chicago Cubs |
|---|
| 28 | - Atlanta Braves |
|---|
| 29 | |
|---|
| 30 | # Sequence of mappings |
|---|
| 31 | --- |
|---|
| 32 | - |
|---|
| 33 | name: Mark McGwire |
|---|
| 34 | hr: 65 |
|---|
| 35 | avg: 0.278 |
|---|
| 36 | - |
|---|
| 37 | name: Sammy Sosa |
|---|
| 38 | hr: 63 |
|---|
| 39 | avg: 0.288 |
|---|
| 40 | |
|---|
| 41 | # Sequence of sequences |
|---|
| 42 | --- |
|---|
| 43 | - [name , hr, avg ] |
|---|
| 44 | - [Mark McGwire, 65, 0.278] |
|---|
| 45 | - [Sammy Sosa , 63, 0.288] |
|---|
| 46 | |
|---|
| 47 | # Mapping of mappings |
|---|
| 48 | --- |
|---|
| 49 | Mark McGwire: {hr: 65, avg: 0.278} |
|---|
| 50 | Sammy Sosa: { |
|---|
| 51 | hr: 63, |
|---|
| 52 | avg: 0.288 |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | # Two documents in a stream |
|---|
| 56 | --- # Ranking of 1998 home runs |
|---|
| 57 | - Mark McGwire |
|---|
| 58 | - Sammy Sosa |
|---|
| 59 | - Ken Griffey |
|---|
| 60 | --- # Team ranking |
|---|
| 61 | - Chicago Cubs |
|---|
| 62 | - St Louis Cardinals |
|---|
| 63 | |
|---|
| 64 | # Documents with the end indicator |
|---|
| 65 | --- |
|---|
| 66 | time: 20:03:20 |
|---|
| 67 | player: Sammy Sosa |
|---|
| 68 | action: strike (miss) |
|---|
| 69 | ... |
|---|
| 70 | --- |
|---|
| 71 | time: 20:03:47 |
|---|
| 72 | player: Sammy Sosa |
|---|
| 73 | action: grand slam |
|---|
| 74 | ... |
|---|
| 75 | |
|---|
| 76 | # Comments |
|---|
| 77 | --- |
|---|
| 78 | hr: # 1998 hr ranking |
|---|
| 79 | - Mark McGwire |
|---|
| 80 | - Sammy Sosa |
|---|
| 81 | rbi: |
|---|
| 82 | # 1998 rbi ranking |
|---|
| 83 | - Sammy Sosa |
|---|
| 84 | - Ken Griffey |
|---|
| 85 | |
|---|
| 86 | # Anchors and aliases |
|---|
| 87 | --- |
|---|
| 88 | hr: |
|---|
| 89 | - Mark McGwire |
|---|
| 90 | # Following node labeled SS |
|---|
| 91 | - &SS Sammy Sosa |
|---|
| 92 | rbi: |
|---|
| 93 | - *SS # Subsequent occurrence |
|---|
| 94 | - Ken Griffey |
|---|
| 95 | |
|---|
| 96 | # Mapping between sequences |
|---|
| 97 | --- |
|---|
| 98 | ? - Detroit Tigers |
|---|
| 99 | - Chicago cubs |
|---|
| 100 | : |
|---|
| 101 | - 2001-07-23 |
|---|
| 102 | ? [ New York Yankees, |
|---|
| 103 | Atlanta Braves ] |
|---|
| 104 | : [ 2001-07-02, 2001-08-12, |
|---|
| 105 | 2001-08-14 ] |
|---|
| 106 | |
|---|
| 107 | # Inline nested mapping |
|---|
| 108 | --- |
|---|
| 109 | # products purchased |
|---|
| 110 | - item : Super Hoop |
|---|
| 111 | quantity: 1 |
|---|
| 112 | - item : Basketball |
|---|
| 113 | quantity: 4 |
|---|
| 114 | - item : Big Shoes |
|---|
| 115 | quantity: 1 |
|---|
| 116 | |
|---|
| 117 | # Literal scalars |
|---|
| 118 | --- | # ASCII art |
|---|
| 119 | \//||\/|| |
|---|
| 120 | // || ||__ |
|---|
| 121 | |
|---|
| 122 | # Folded scalars |
|---|
| 123 | --- > |
|---|
| 124 | Mark McGwire's |
|---|
| 125 | year was crippled |
|---|
| 126 | by a knee injury. |
|---|
| 127 | |
|---|
| 128 | # Preserved indented block in a folded scalar |
|---|
| 129 | --- |
|---|
| 130 | > |
|---|
| 131 | Sammy Sosa completed another |
|---|
| 132 | fine season with great stats. |
|---|
| 133 | |
|---|
| 134 | 63 Home Runs |
|---|
| 135 | 0.288 Batting Average |
|---|
| 136 | |
|---|
| 137 | What a year! |
|---|
| 138 | |
|---|
| 139 | # Indentation determines scope |
|---|
| 140 | --- |
|---|
| 141 | name: Mark McGwire |
|---|
| 142 | accomplishment: > |
|---|
| 143 | Mark set a major league |
|---|
| 144 | home run record in 1998. |
|---|
| 145 | stats: | |
|---|
| 146 | 65 Home Runs |
|---|
| 147 | 0.278 Batting Average |
|---|
| 148 | |
|---|
| 149 | # Quoted scalars |
|---|
| 150 | --- |
|---|
| 151 | unicode: "Sosa did fine.\u263A" |
|---|
| 152 | control: "\b1998\t1999\t2000\n" |
|---|
| 153 | hex esc: "\x0d\x0a is \r\n" |
|---|
| 154 | single: '"Howdy!" he cried.' |
|---|
| 155 | quoted: ' # not a ''comment''.' |
|---|
| 156 | tie-fighter: '|\-*-/|' |
|---|
| 157 | |
|---|
| 158 | # Multi-line flow scalars |
|---|
| 159 | --- |
|---|
| 160 | plain: |
|---|
| 161 | This unquoted scalar |
|---|
| 162 | spans many lines. |
|---|
| 163 | quoted: "So does this |
|---|
| 164 | quoted scalar.\n" |
|---|
| 165 | |
|---|
| 166 | # Integers |
|---|
| 167 | --- |
|---|
| 168 | canonical: 12345 |
|---|
| 169 | decimal: +12_345 |
|---|
| 170 | sexagesimal: 3:25:45 |
|---|
| 171 | octal: 014 |
|---|
| 172 | hexadecimal: 0xC |
|---|
| 173 | |
|---|
| 174 | # Floating point |
|---|
| 175 | --- |
|---|
| 176 | canonical: 1.23015e+3 |
|---|
| 177 | exponential: 12.3015e+02 |
|---|
| 178 | sexagesimal: 20:30.15 |
|---|
| 179 | fixed: 1_230.15 |
|---|
| 180 | negative infinity: -.inf |
|---|
| 181 | not a number: .NaN |
|---|
| 182 | |
|---|
| 183 | # Miscellaneous |
|---|
| 184 | --- |
|---|
| 185 | null: ~ |
|---|
| 186 | true: boolean |
|---|
| 187 | false: boolean |
|---|
| 188 | string: '12345' |
|---|
| 189 | |
|---|
| 190 | # Timestamps |
|---|
| 191 | --- |
|---|
| 192 | canonical: 2001-12-15T02:59:43.1Z |
|---|
| 193 | iso8601: 2001-12-14t21:59:43.10-05:00 |
|---|
| 194 | spaced: 2001-12-14 21:59:43.10 -5 |
|---|
| 195 | date: 2002-12-14 |
|---|
| 196 | |
|---|
| 197 | # Various explicit tags |
|---|
| 198 | --- |
|---|
| 199 | not-date: !!str 2002-04-28 |
|---|
| 200 | picture: !!binary | |
|---|
| 201 | R0lGODlhDAAMAIQAAP//9/X |
|---|
| 202 | 17unp5WZmZgAAAOfn515eXv |
|---|
| 203 | Pz7Y6OjuDg4J+fn5OTk6enp |
|---|
| 204 | 56enmleECcgggoBADs= |
|---|
| 205 | application specific tag: !something | |
|---|
| 206 | The semantics of the tag |
|---|
| 207 | above may be different for |
|---|
| 208 | different documents. |
|---|
| 209 | |
|---|
| 210 | # Global tags |
|---|
| 211 | %TAG ! tag:clarkevans.com,2002: |
|---|
| 212 | --- !shape |
|---|
| 213 | # Use the ! handle for presenting |
|---|
| 214 | # tag:clarkevans.com,2002:circle |
|---|
| 215 | - !circle |
|---|
| 216 | center: &ORIGIN {x: 73, y: 129} |
|---|
| 217 | radius: 7 |
|---|
| 218 | - !line |
|---|
| 219 | start: *ORIGIN |
|---|
| 220 | finish: { x: 89, y: 102 } |
|---|
| 221 | - !label |
|---|
| 222 | start: *ORIGIN |
|---|
| 223 | color: 0xFFEEBB |
|---|
| 224 | text: Pretty vector drawing. |
|---|
| 225 | |
|---|
| 226 | # Unordered sets |
|---|
| 227 | --- !!set |
|---|
| 228 | # sets are represented as a |
|---|
| 229 | # mapping where each key is |
|---|
| 230 | # associated with the empty string |
|---|
| 231 | ? Mark McGwire |
|---|
| 232 | ? Sammy Sosa |
|---|
| 233 | ? Ken Griff |
|---|
| 234 | |
|---|
| 235 | # Ordered mappings |
|---|
| 236 | --- !!omap |
|---|
| 237 | # ordered maps are represented as |
|---|
| 238 | # a sequence of mappings, with |
|---|
| 239 | # each mapping having one key |
|---|
| 240 | - Mark McGwire: 65 |
|---|
| 241 | - Sammy Sosa: 63 |
|---|
| 242 | - Ken Griffy: 58 |
|---|
| 243 | |
|---|
| 244 | # Full length example |
|---|
| 245 | --- !<tag:clarkevans.com,2002:invoice> |
|---|
| 246 | invoice: 34843 |
|---|
| 247 | date : 2001-01-23 |
|---|
| 248 | bill-to: &id001 |
|---|
| 249 | given : Chris |
|---|
| 250 | family : Dumars |
|---|
| 251 | address: |
|---|
| 252 | lines: | |
|---|
| 253 | 458 Walkman Dr. |
|---|
| 254 | Suite #292 |
|---|
| 255 | city : Royal Oak |
|---|
| 256 | state : MI |
|---|
| 257 | postal : 48046 |
|---|
| 258 | ship-to: *id001 |
|---|
| 259 | product: |
|---|
| 260 | - sku : BL394D |
|---|
| 261 | quantity : 4 |
|---|
| 262 | description : Basketball |
|---|
| 263 | price : 450.00 |
|---|
| 264 | - sku : BL4438H |
|---|
| 265 | quantity : 1 |
|---|
| 266 | description : Super Hoop |
|---|
| 267 | price : 2392.00 |
|---|
| 268 | tax : 251.42 |
|---|
| 269 | total: 4443.52 |
|---|
| 270 | comments: |
|---|
| 271 | Late afternoon is best. |
|---|
| 272 | Backup contact is Nancy |
|---|
| 273 | Billsmer @ 338-4338. |
|---|
| 274 | |
|---|
| 275 | # Another full-length example |
|---|
| 276 | --- |
|---|
| 277 | Time: 2001-11-23 15:01:42 -5 |
|---|
| 278 | User: ed |
|---|
| 279 | Warning: |
|---|
| 280 | This is an error message |
|---|
| 281 | for the log file |
|---|
| 282 | --- |
|---|
| 283 | Time: 2001-11-23 15:02:31 -5 |
|---|
| 284 | User: ed |
|---|
| 285 | Warning: |
|---|
| 286 | A slightly different error |
|---|
| 287 | message. |
|---|
| 288 | --- |
|---|
| 289 | Date: 2001-11-23 15:03:17 -5 |
|---|
| 290 | User: ed |
|---|
| 291 | Fatal: |
|---|
| 292 | Unknown variable "bar" |
|---|
| 293 | Stack: |
|---|
| 294 | - file: TopClass.py |
|---|
| 295 | line: 23 |
|---|
| 296 | code: | |
|---|
| 297 | x = MoreObject("345\n") |
|---|
| 298 | - file: MoreClass.py |
|---|
| 299 | line: 58 |
|---|
| 300 | code: |- |
|---|
| 301 | foo = bar |
|---|
| 302 | |
|---|