YAML

From Wikipedia, the free encyclopedia

YAML is a human-readable data serialization format that takes concepts from languages such as XML, C, Python, Perl, as well as the format for electronic mail as specified by RFC 2822. YAML was first proposed by Clark Evans in 2001, who designed it together with Ingy döt Net and Oren Ben-Kiki.

YAML is a recursive acronym meaning "YAML Ain't Markup Language". Early in its development, YAML was said to mean "Yet Another Markup Language", retronymed to distinguish its purpose as data-centric, rather than document markup. However since XML (a true document markup language) is frequently used for data serialization, it is reasonable to consider YAML a lightweight markup language.

Contents

[edit] Features

YAML was created with the belief that all data can be adequately represented by combinations of lists, hashes (mappings), and scalar (single value) data. The syntax is relatively straightforward and was designed with human readability in mind, but also to be easily mapped to data types common to most high-level languages. In addition, YAML uses a notation based on indentation and/or a set of sigil characters distinct from those used in XML, making the two languages easily composable.

  • YAML streams are encoded using the set of printable Unicode characters, either in UTF-8 or UTF-16
  • Whitespace indentation is used to denote structure; however tab characters are never allowed as indentation
  • List members are denoted by a leading hyphen ( - ) with one member per line, or enclosed in square brackets ( [   ] ) and separated by comma space ( ,   ).
  • Hashes are represented using the colon space ( :   ) in the form key: value, either one per line or enclosed in curly braces ( {   } ) and separated by comma space ( ,   ).
  • A hash key value is prefixed with a question mark ( ? ), allowing for complex keys to be represented unambiguously.
  • Simple values (scalars) are ordinarily unquoted, but may be enclosed in double-quotes ( " ), or single-quotes ( ' ).
  • Within double-quotes, special characters may be represented with C-style escape sequences starting with a backslash ( \ ).
  • Block scalars are delimited with indentation with optional modifiers to preserve ( | ) or fold ( > ) newlines
  • Multiple documents within a single stream are separated by three hyphens ( --- ); three periods ( ... ) optionally end a document within a stream
  • Repeated nodes are initially denoted by an ampersand ( & ) and thereafter referenced with an asterisk ( * )
  • Comments are denoted by the number sign ( # ) and continue until the end of the line
  • Nodes may be labeled with a type or tag using the exclamation point ( ! ) followed by a string which can be expanded into a URI.
  • YAML documents in a stream may be preceded by directives composed of a percent sign ( % ) followed by a name and space delimited parameters. Two directives are defined in YAML 1.1:
    • The %YAML directive is used to identify the version of yaml in a given document.
    • The %TAG directive is used as a shortcut for URI prefixes. These shortcuts may then be used in node type tags.

YAML requires that colons and commas used as list separators be followed by a space so that scalar values containing embedded punctuation (such as 5,280 or http://www.wikipedia.org) can generally be represented without needing to be enclosed in quotes.

Two additional sigil characters are reserved in YAML for possible future standardisation: the at sign ( @ ) and accent grave ( ` ).

[edit] Examples

[edit] Lists

--- # Favorite movies, block format
- Casablanca
- Spellbound
- Notorious
--- # Shopping list, inline format
[milk, bread, eggs, juice]

[edit] Hashes

--- # Block
name: John Smith
age: 33
--- # Inline
{name: John Smith, age: 33}

[edit] Block Literals

[edit] Newlines preserved

--- |
  There was a young fellow of Warwick
  Who had reason for feeling euphoric
      For he could, by election
      Have triune erection
  Ionic, Corinthian, and Doric

[edit] Newlines folded

--- >
  Wrapped text
  will be folded
  into a single
  paragraph
  
  Blank lines denote
  paragraph breaks

[edit] Lists of Hashes

- {name: John Smith, age: 33}
- name: Mary Smith
  age: 27

[edit] Hashes of Lists

men: [John Smith, Bill Jones]
women:
  - Mary Smith
  - Susan Williams

[edit] Implementations

Bindings for YAML exist for the following languages:

[edit] See also

Other simplified markup languages include:

[edit] External links