Skip to main content

YAML Processes

YAML Process Flow

YAML follows a standard procedure for Process flow.

The Representation Node Graph is the representations of native data structure in YAML as nodes.

The YAML process flow includes mappings, sequences, and scalar quantities that are serialized to create a serialization tree.

note

With serialization, objects are converted into streams of bytes.

The reverse procedure parses the byte stream into a serialized event tree. Next, the nodes are converted into a graph of nodes. These values are then converted into a native YAML data structure.

![imgs/007_img_yaml_process_flow.jpg](Process Flow of YAML)

The information in YAML is used in two ways: machine processing and human consumption.

The processor in YAML is used as a tool for the procedure of converting information between complementary views in the above diagram.

YAML includes a serialization procedure to represent data objects in serial format. The processing of YAML information includes three stages:

  1. Representation
  2. Serialization
  3. Presentation and parsing

Let's see each stage in details.

Representation

YAML represents the data structure using three kinds of nodes:

  • scalar
  • sequence
  • mapping*
note

You can learn more about datatypes in YAML in the Datatypes Chapter

Scalars

Scalars represent standard values of strings, integers, dates and atomic data types.

note

YAML also includes nodes which specify the data type structure.

Sequence

Sequence refers to the ordered number of entries, which maps the unordered association of key value pair.

product:
- sku : BL123D
quantity : 4
description : Basketball
price : 250.00
- sku : BL3214H
quantity : 1
description : Super Shoes
price : 99.00

Mapping

Mapping on the other hand represents dictionary data structure or hash table.

batchLimit: 1000
threadCountLimit: 2
key: value
keyMapping: <What goes here?>

Serialization

Serialization process is required in YAML that eases human friendly key order and anchor names.

The result of serialization is a YAML serialization tree.

It can be traversed to produce a series of event calls of YAML data.

An example of serialization is shown below:

consumer:
class: 'AppBundle\Entity\consumer'
attributes:
filters: ['customer.search', 'customer.order', 'customer.boolean']
collectionOperations:
get:
method: 'GET'
normalization_context:
groups: ['customer_list']
itemOperations:
get:
method: 'GET'
normalization_context:
groups: ['customer_get']

Presentation

The final output of YAML serialization is called presentation.

It represents a character stream in a human friendly manner.

YAML processor includes various presentation details for creating stream, handling indentation and formatting content.

This complete process is guided by the preferences of user.

An example for YAML presentation process is the result of JSON value created:

{
"consumer": {
"class": "AppBundle\\Entity\\consumer",
"attributes": {
"filters": [
"customer.search",
"customer.order",
"customer.boolean"
]
},
"collectionOperations": {
"get": {
"method": "GET",
"normalization_context": {
"groups": [
"customer_list"
]
}
}
},
"itemOperations": {
"get": {
"method": "GET",
"normalization_context": {
"groups": [
"customer_get"
]
}
}
}
}
}

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.

The parsing procedure may fail due to malformed input.

This is basically a procedure to check whether YAML is well-formed or not.

For example:

---
environment: production
classes:
nfs::server:
exports:
- /srv/share1
- /srv/share3
parameters:
paramter1
note

Remember that the three dashes represent the beginning of a document with various attributes defined later.