Deep dive into YAML and Its use
A simple human-readable lang to share/store data, YAML has features that come from XML, HTML, and other programming languages. YAML is also a doppelganger of JSON but YAML has better readability and is more user-friendly, so JSON files are valid in YAML., It's called YAML ain't another markup language because it can store the document and the objects also (Yaml is case-sensitive) One of the most common uses of yaml is creating configuration files which are also used for Kubernetes because of its flexibility and accessibility YAML is used to create the automation processes.
Data-Serialization :
Serialization is a type of language format that is used to convert the object and transmit it to a file, database, or stream of bytes. When we want to send data from one machine to another machine, we need the data to be in binary representation.
It converts it into a stream of bytes and stores it in yaml, data file, memory
So basically we have an object and we want to share it with the other computers but the format is different so we convert it into the YAML file and share it so in we're converting it into a YAML file and the format would be one only and converting the yaml file back into the object is deserialization.
YAML Features:
:-Simple and easy to read
:-Indentation is important - It has a strict syntax
:-Easily convertible to JSON/XML
:-More powerful when using complex data
:-Parsers etc various tools available
:-Suitable for configuration settings
:-Support for major programming languages
"store": "This is the data for storing"
Key-value pair:
The key-value pair is a data structure consisting of the key with its value, The key is for the identification of the value and the data type can be any type.
Data-Types in YAML
#String data types
me: "siddharth"
hobbies: "reading, travelling"
job: "swe"
bio: |
hey i like learning new things.
#Writing a single line in a multiple line
message: >
this is a single
line text i'm writing in a
multiple line
#same as
this is a single line text i'm writing in a multiple line
#in the object it will be in a single line
Specifying the Type:
To declare the value we can specify the data-types
# Specifiy the Type
binaryNum: !!int 0b1123
octalNum: !!int 0343
hexaDEc: !!int 0x32
# for storing the value with comma ,
commaValue: !! int $89_000 # $89,000
#Floating point numbers
marks: !!float 65.90
infinite: !!float .inf
not a num: .nan
Advance Data-Type:
name: Siddharth
role:
age: 103
job: student
#same as
name: Siddharth
role: {age: 103, job: student}
pair example: !!pairs [job: student, job: teacher]
# this will be an array of hashtables
Anchor:
In Anchor, We use the same property in a different key so that we don't need to create it multiple times.
liking: &likes
fruit: apple
dislikes: guava
person1:
name: nihal
<<: *likes
# This will look like
person1:
name: nihal
fruit: apple
dislikes: guava