YAML: Difference between revisions
No edit summary |
(→String) |
||
Line 76: | Line 76: | ||
text section | text section | ||
</pre> | </pre> | ||
=Data Types= | =Data Types= |
Revision as of 22:15, 26 January 2016
External
Overview
YAML is a human-readable data serialization format. YAML syntax was designed to easily map on scalars, list and associative arrays. It is well suited for hierarchical data representation. It does not use enclosures such as quotation marks, brackets, braces and open/close tags, which can be hard fro the human eye to balance in nested hierarchies. Data structure hierarchy is maintained by outline indentation. The specific number of spaces in the indentation is not important as long as parallel elements have the same left justification, and the hierarchically nested elements are indented further.
Strings do not require enclosure in quotations.
The format has support for references, where sections in the document can be referenced, thus eliminating redundancy.
Multiple documents can exist in a single file/stream and they are separated by "---".
An optional "..." can be used at then of the file - useful for signaling an end in streamed communication without closing the pipe.
List
List elements are designated by hyphen + space:
- Audi - Mercedes - BMW
Optional In-Line List Format
List elements are enclosed in brackets, and the list elements are separated by comma + space.
Associative Array
Keys are separated from values by a colon + space.
name: Audi color: black capacity: 5
Optional In-Line Associative Array Format
Associative array element are enclosed in braces, and they key: value pairs are separated by comma + space.
List of Associative Arrays
- country: AU price: 6990000 - country: AT price: 4990000 - country: BE price: 4990000
String
Strings do not require quotation.
Multi-line strings can be written using the '|' character followed by a new line. Trailing white space is stripped.
data: | This is a multi-line text section
The '>' character followed by a new line folds all the new lines, after removing trailing white space.
data: > This is another multi-line text section
Data Types
YAML auto-detects the datatype
Core Data Types
Strings, ints, floats, lists and maps.
a: 123 # an integer b: "123" # a string, disambiguated by quotes c: 123.0 # a float d: !!float 123 # a 'casted' float e: !!str 123 # a 'casted' string