http://www.yaml.org/ YAML is text-based data format. It uses simple block spacing with a few symbols to represent data and relationships. The advantage is quick reading and understanding.
%YAML 1.1
---
MyCollection:
Apples:
- Red
- Yellow
Grapes:
- Green
- Purple
Oranges:
- Orange
...
The simplest form contains contains either a label or value on a value. Labels end with a :. Values are pretty much everything else. Here is shown a dictionary with a label and value that is another dictionary. The inner dictionary contains labels which have a list as a value. The list' is what holds the multiple values for the dictionary'' label as labels cannot be repeated. The indentation is important as it marks lines as belonging to previous. The YAML format also allows for you to collapse labels and values into single lines.
%YAML 1.1
---
MyCollection:
Apples: [Red,Yellow]
Grapes: [Green,Purple]
Oranges: [Orange]
...
This more concise form is identical to the prior. Each list has been consilidated with the format [value,value,...]. Each dictionary could have been consilidatded with the format {label:value,...}.
You may have noticed that the data did not need to be in quotes. The exception is when using the reserved formatting characters. Values may also be marked as specific datatype when it may not be clear.
!!str!!null!!int!!float!!bool%YAML 1.1
---
ToDo:
Repair Computer: >
Computer needs new video card and hard drive.
Check websites for best deals before purchasing.
Organize Space: |
Organize loose notes
Put away loose items
...
YAML does allow values to span multiple lines. The > and | tells us that following indented lines are one value for this line. A > tells the parser to collapse all the following indented lines. A | tells the parser to preserve all formating for the following indented lines.
As you can see, YAML is simple and readable. This was only a quick intro and was meant to help review the basics.
More is in the works on YAML: Creating a Basic Parser with http://www.pyyaml.org/ PyYaml and even Creating a GUI-based frontend with http://www.wxpython.org/ WxPython.
Contact with Questions or Feedback: Send email to tjaustinbardo AT gmail DOT com
modified: August 10, 2008, at 06:16 PM