Sie sind auf Seite 1von 18

YAML

What is a data serialization language?


• A language used to convert or represent structured data
or objects as a series of characters that can be stored on
a disk.
• Examples:
• CSV – Comma separated values
• XML – Extensible markup language
• JSON – JavaScript object notation
• YAML – YAML ain’t markup language
What is YAML?
YAML includes a markup language with important construct, to
distinguish data-oriented language with the document markup. The
design goals and features of YAML are given below −
Matches native data structures of agile methodology and its
languages such as Perl, Python, PHP, Ruby and JavaScript

YAML data is portable between programming languages

Includes data consistent data model

Easily readable by humans

Supports one-direction processing


Why YAML ifXML?
• Unlike XML which is not easily readable by humans, YAML
was created to be human-friendly and integrate easily with
modern programming languages.
• Unlike with XML, YAML was intended to simplify the viewing
and understanding of config files, log files, object persistence,
and messaging, to allow the programmer to spend more time
programming and less time formatting data.
• JSON is only readable whereas YAML can be readable as well
as editable. JSON is a subset of YAML so that YAML parsers
can be able to parse JSON. YAML doesn't use any extra
delimiters, so it is more light-weight than XML and JSON.
YAML Design Goals
• As stated in the YAML official specification, the design
goals for YAML in decreasing priority are:
1. YAML is easily readable by humans
2. YAML data is portable between programming languages
3. YAML matches the native data structures of agile languages.
4. YAML has a consistent model to support generic tools.
5. YAML supports one-pass processing.
6. YAML is expressive and extensible.
7. YAML is easy to implement and use.
Basic YAML SyntaxRules
• Documents begin with --- and end with …
• Indentation of lines denotes the structure within the
document.
• Comments begin with #
• Members of lists begin with –
• Key value pairs use the following syntax
• <key>: <value>
Basic YAML SyntaxRules
• Example:

---
Student-Id: 11223344
First-Name: John
Last-Name: Smith

Phone-numbers:
- 281.555.7689
- 713.555.8967
- 832.555.9980

Addresses:
- street: 123 Main St.
city: Houston
state: TX
...
Synopsis of YAML Basic Elements
The synopsis of YAML basic elements is given here:

• Comments in YAML begins with the (#) character.

• List members are denoted by a leading hyphen (-).


• List members are enclosed in square brackets and
separated by commas.

• Associative arrays are represented using colon ( : ) in


the format of key value pair. They are enclosed in
curly braces {}.

• Multiple documents with single streams are separated


with 3 hyphens (---).
• The processing of YAML information includes
three stages: Representation, Serialization,
Presentation and parsing.
Representation: YAML represents the data
structure using three kinds of nodes: sequence,
mapping and scalar.
• Sequence: Sequence refers to the ordered
number of entries, which maps the unordered
association of key value pair You can specify a
sequence using -.
Mapping
• You can specify a key-value map using :. Each
member of the map should be on a new line.

Inline Sequence
• You can make a sequence in a short way.
Aliasing and Anchoring
• You can give an alias to a specific item using &
and name. Then, you can refer/anchor it with
* and its name.
Merging
• If you alias a map, you can merge that into the
current map with <<.
• Multilines
You can put multilines just by adding it. In this
case, one line break is ignored and consider it as
one line. In this example, there is no \n between
serialization and standard.
• Commenting
You can specify a comment using # to add an
additional information
• Serialization:Serialization process is required
in YAML that eases human friendly key order
and anchor names
• Presentation: The final output of YAML serialization
is called presentation. It represents a character
stream in a human friendly manner. An example for
YAML presentation process is the result of JSON
value created.
• Parsing: Parsing is the inverse process of
presentation; it includes a stream of characters
and creates a series of events. It discards the
details introduced in the presentation process
which causes serialization events.

Das könnte Ihnen auch gefallen