What is YAML ?
YAML is a data serialization language that is often used for writing configuration files. Depending on whom you ask, YAML stands for yet another markup language or YAML ain’t markup language (a recursive acronym), which emphasizes that YAML is for data, not documents.
previously it was known as "Yet Another Markup Language"
Why YAML ain't Markup Language!!
->firstly what is markup language??
A markup language is a computer language that uses tags to define elements within a document. It is human-readable, meaning markup files contain standard words, rather than typical programming syntax.
ex:-HTML is very popular markup language!
but YAML isn't works on documentation it's simply a human readable data serialization language so it named as YAML ain't Markup Language
What is data serialization?
-> Data serialization is the process of converting data objects present in complex data structures into a byte stream for storage, transfer and distribution purposes on physical devices.
-> in simple terms look at real life example you have an idea of some project so you have thought on it and then you have noted down the points on it and you have described it on the mail to your friend now your friend will read the email and will understand about it what your plan is about.
->so in the above example the process that you have done to describing is serialization and your friend have de-serialized it to get the idea about it
Why do we need data serialization?
->Serialization enables us to save the state of an object and recreate the object in a new location. Serialization encompasses both the storage of the object and exchange of data. Since objects are composed of several components, saving or delivering all the parts typically requires significant coding effort, so serialization is a standard way to capture the object into a sharable format.
some data serialization languages:
- Json(Java script Object Notation)
- XML (Extensible Markup Language)
Benefits and Usages of YAML
Benefits:-
- Simple and Easy to read
- It's strict syntax provides us surety about proper indentation
- There are some tool they can convert yaml to json as well as xml
- More powerful when representing complex data
- Parsing is Easy
Usage:-
- mainly to write configuration files for Docker , Kubenetes etc.
- maintaining logs and caches of the applications
Syntax of YAML:-
->There’s another small quirk to YAML. All YAML files (regardless of their association with Ansible or not) can optionally begin with --- and end with ... This is part of the YAML format and indicates the start and end of a document.
->All members of a list are lines beginning at the same indentation level starting with a "- " (a dash and a space):
->A dictionary is represented in a simple key: value form (the colon must be followed by a space)
-> Values can span multiple lines using | or >. Spanning multiple lines using a “Literal Block Scalar” | will include the newlines and any trailing spaces. Using a “Folded Block Scalar” > will fold newlines to spaces; it’s used to make what would otherwise be a very long line easier to read and edit. In either case the indentation will be ignored. Examples are:
Datatypes in YAML
- string
- integer
- date and time
- floating point numbers
- null
- boolean
Some advanced Datatypes in YAML
- sequences
- maps
- pairs
- sets
- dictionary
What if you want to re-use particular property in YAML?
->the given below way you can reuse and also over-ride it
YAML to JSON convertor
-Tool
-YAML file
->JSON converted file
->This is the tool demo:-
What if you are bored by checking the syntax and writing the YAML files which are having strict indentation?
-here are some tools that can make it easy
-To validate your yaml file
-Datree
-Easy IDE to write your YAML files
-Lens
Source code
->Link
Shout out to one and only Kunal Kushwaha for teaching us