YAML Examples for Developers

1. Invoice

YAML

------ !<tag:clarkevans.com,2002:invoice>invoice: 34843date : 2001-01-23bill-to: &id001  given : Chris  family : Dumars  address:     lines: |       458 Walkman Dr.       Suite #292     city : Royal Oak     state : MI     postal : 48046ship-to: *id001product:  - sku : BL394D    quantity : 4    description : Basketball    price : 450.00 - sku : BL4438H   quantity : 1   description : Super Hoop   price : 2392.00tax : 251.42total: 4443.52comments:   Late afternoon is best.   Backup contact is Nancy   Billsmer @ 338-4338.

Corresponding JSON:

{ "invoice": 34843, "date": "2001-01-23", "bill-to": { "given": "Chris", "family": "Dumars", "address": {     "lines": "458 Walkman Dr.\nSuite #292\n",     "city": "Royal Oak",     "state": "MI",     "postal": 48046  } }, "ship-to": { "given": "Chris", "family": "Dumars", "address": {    "lines": "458 Walkman Dr.\nSuite #292\n",    "city": "Royal Oak",    "state": "MI",    "postal": 48046   } }, "product": [  {     "sku": "BL394D",     "quantity": 4,     "description": "Basketball",     "price": 450.0   }, {     "sku": "BL4438H",     "quantity": 1,     "description": "Super Hoop",     "price": 2392.0   } ], "tax": 251.42, "total": 4443.52, "comments": "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338."}

2.  Log File

YAML

Time: 2001-11-23 15:01:42 -5User: edWarning:    This is an error message    for the log fileTime2: 2001-11-23 15:02:31 -5User2: edWarning2:    A slightly different error    message.Date3: 2001-11-23 15:03:17 -5User3: edFatal:    Unknown variable "bar"Stack:   - file: TopClass.py     line: 23     code: |         x = MoreObject("345\n")  - file: MoreClass.py    line: 58    code: |-         foo = bar

Corresponding JSON:

{ "Time": "2001-11-23 15:01:42 -0500", "User": "ed", "Warning": "This is an error message for the log file", "Time2": "2001-11-23 15:02:31 -0500", "User2": "ed", "Warning2": "A slightly different error message.", "Date3": "2001-11-23 15:03:17 -0500", "User3": "ed", "Fatal": "Unknown variable \"bar\"", "Stack": [    {      "file": "TopClass.py",      "line": 23,      "code": "x = MoreObject(\"345\\n\")\n"    }, {      "file": "MoreClass.py",      "line": 58,      "code": "foo = bar"   } ]}