http://yaml.org/
Yaml: Yaml Ain ' t Markup Language whatIt's: Yaml is a human friendly data serialization standard for all p Rogramming languages.
YAML (yet another Markup Language) (pronunciation/?jæm?l/)
A programming language used to express data sequences based on the easy-to-read Unicode, which is easy to interact with the scripting language.
Adaptation scenarios
- Scripting language: Because of its simplicity and low parsing costs, YAML is particularly well-suited for use in scripting languages
- Serialization: Yaml is a direct-to-host language data type, which is more suitable for serialization.
- Config file: Writing YAML is much faster than writing XML (no need to focus on tags or quotes) and is more powerful than INI documentation. Because of compatibility issues, data flow between different languages is not recommended for YAML.
YAML syntax
- Use spaces space to indent the hierarchy, the indentation between different levels can use a different number of spaces, but the same layer elements must be left-aligned, that is, the number of spaces preceding the same (can not use tab, the individual System tab corresponding to the number of space may be different, resulting in hierarchy confusion)
- ' # ' for comments, only single-line comments, from # Start to end of line
- A dash followed by a space (a dash and space) represents the list
- Use colons and spaces to denote key-value pairs Key:value
- Simple data (scalars, scalar data) can be enclosed in quotation marks, including string data. Used as string data in single or double quotation marks, with C-style escape characters in single or double quotes
- Case sensitive
- Using indents to represent hierarchical relationships
- The TAB key is not allowed when indenting, only spaces are allowed.
- The number of spaces you indent is not important, as long as the same level elements are left aligned
This article describes the syntax of YAML, taking the implementation of JS-YAML as an example. You can go to the online Demo to verify the example below.
YAML supports three types of data structures.
- Object: A collection of key-value pairs, also known as mappings (mapping)/hashes (hashes)/dictionaries (dictionary)
- Arrays: A set of sequential values, also known as sequences (sequence)/lists (list)
- Pure weight (scalars): a single, non-divided value
These three data structures are described below.
Three, array
A set of lines at the beginning of a conjunction line that forms an array.
- Cat- Dog- Goldfish
Switch to JavaScript as follows.
[ ‘Cat‘, ‘Dog‘, ‘Goldfish‘ ]
A child member of a data structure is an array, and you can indent a space below the item.
- - Cat - Dog - Goldfish
Switch to JavaScript as follows.
[ [ ‘Cat‘, ‘Dog‘, ‘Goldfish‘ ] ]
Arrays can also be used in inline notation.
animal: [Cat, Dog]
Switch to JavaScript as follows.
{ animal: [ ‘Cat‘, ‘Dog‘ ] }
Mapping scalars to sequences simple data list key value pair
American
-Boston Red Sox
-Detroit Tigers
-New York Yankees
National
-New York Mets
-Chicago Cubs
-Atlanta Braves
. yml file formats