Y A M L

Yaml Ain't Markup Language

ยท

3 min read

Y A M L

Previously YAML was known as Yet Another Markup Language. But now it is called Yaml Ain't Markup Language.

  • YAML is not a programming language

  • YAML is a human-readable data serialization language

  • It is similar to XML & JSON Data type language.

  • It has a strict syntax and Indentation is important

  • it can be easily converted into JSON or XML files

  • The standard format to transfer the data

Key Value Pairs-

Key Value pairs are separated by 'Colon'. The left side of the ' : ' is Key and the right side of the ' : ' is the value. You have to use space after ":" otherwise your content is invalid.

This is key : this is value
1 : this is one

In YAML, you can write 'string' without quotes as well.

comments-

In YAML only you can use a single-line comment by typing '#' .

#this is a comment

Objects-

Here's 'Tourist Places' is 'Object'.

Tourist Places:
            Himachal Pradesh : Shimla
            Chandigarh : Rock Garden
            New Delhi : India Gate

Lists-

The list is represented by ' - '

microservices :
            -app : user-auth #because of '-' this is called a list
            port : 80
            version : 1.7

same as :

list also :
   -one
   -two
   -three

The List under List:

microservices:
            -app : user-auth #this is a list
            port : 80
            version : [ 1.7, 1.9, 2.0 ]  #this is also list but under list

Booleans-

Booleans in YAML: on/off, True/False, Yes/No

microservices:
            -app : user-auth
            port : 80
            deployed : off #here this is called boolean

Multiline String-

In YAML you cannot write multiple lines without ' | '

multiline string :  | #by the use of '|' you can type multiline string
this is
a multi-
line string.

If you have a single line string that has too many words use '>' to put all content in one line

single-line string : > #by the use of '>' you can type single-line string
 this all 
 content 
 will appears in
 the single 
 line .

Environment Variables-

commands :
   -/bin/sh
   - -ec
   - >-
   mysql -h 127.0.0.1 -u root -p$MYSQL_ROOT_PASSWORD_E
   'SELECT 1'
#env var $MY_SQL_ROOT_PASSWORD

SKDJ

Placeholders-

It is a special string that can be replaced with a value at runtime.

database :
   name : ${{ database_name }}

When this file is processed, the value of the 'database_name' env. var. will be substituted for the placeholders. This allows you to use env. var. to config your YAML file.

Multiple YAML documents-

This means you can store two files in one file separated by '---'

apiVersion : v1  
kind : configMap 
metadata :         
        name : Mosquito-config-file
data :
  mosquitoconf : |
   log_dost stdout
   log_type shell
   listener 9001
---
apiVersion : v2
kind : secret
metadata :
        name : Mosquito-secret-file
        type : Opaque      
        data : NULL

A Real World Example :

apiVersion : v1     # key value pairs
kind : configMap 
metadata :          # object
        name : nginx
        labels :    #object
        app : nginx
spec :              #object
  containers :      #list of objects
            - name :nginx-container
            - image : nginx
            - ports :   #list
            - data : NULL

Here you can see the difference between YAML, JSON and XML file

XML is similar to HTML and YAML is human readable.

That's all about YAML. Thank You for Reading this ๐Ÿš€.

Click here to check Your YAML file :

Click Here to Connect with me :

Did you find this article valuable?

Support Abhishek by becoming a sponsor. Any amount is appreciated!

ย