YAML file in Easy Way

YAML file in Easy Way

  • What is YAML file?

    • It is basically a data format used to exchange data
    • It is similar to XML and JSON
    • Remember: It is not a programming language
    • Note: In YAML, you can only store data and not commands
  • Data serialisation:

    • It is a process of converting the data objects that is present in some complex data structure into stream of bytes that can be used to transfer data in physical devices
    • Remember: Object= code + data
    • Data Serialiser:
  • Data Serialisation language:

    • Language that can be used to represent the data in text format
      • e.g. YAML, JSON, XML (Extensible Markup Language)
  • Why YAML ain't a markup language?

    • Markup languages such as HTML are used to store documents. But in YAML you can also store object data
    • It is used in Configuration file -> Docker/ Kubernetes etc.
    • Used in logs, caches etc
    • image.png
  • Benefits of YAML:

    • Simple and easy to read
    • It has a strict syntax (Here indentation is important)
    • Easily convertible to JSON, XML
    • Most languase use YAML
    • More powerful when representing complex data
    • Parsing is easy
      • Parsing basically means reading the data
  • YAML File:

    • Remember: YAML is case sensitive
    • Key-Value pair:

      • e.g. "apple" : " I am a red fruit"
      • Remember: This particular thing is not stored in hashmaps and stuffs, this is just a textual representation
        • You can use this file and convert into a hashmap out of it
    • Lists:

      • You represent it using dash (-)
      • -apple
        -mango
        -banana
        
    • Block:

      • cities:
        -new delhi
        -mumbai
        -gujrat
        
    • Variables:

      • Strings:
        • e.g.-
        • myself : Amaan
          fruit : "apple"
          job : 'student'
          bio : | //This is the Way to write in para
          hey I am Amaan and right now i am
          learning DevOps. Super Awsome learning 
          experience
          message : > //This is the Way to write in a single line
          This will be
          all in single line
          
    • Specific Datatypes:

      • int:
        • e.g.
        • zero:!! int 0
          positiveNume:!! int 45
          negativeNum:!! int -45
          binaryNum:!! int 0b11001 //Starts with 0b
          octalNum:!! 06575 //Starts with 0
          hexa:!! int 0x45 //Starts with 0x
          
      • Float:
        • marks:!!float 56.89
          infinite:!! float.inf
          notaNum: .nan
          
      • Boolean:
        • booleanValue:!! bool No
          
      • String:
        • message:!!str this is a string
          
      • Null:
        • surname:!!null Null
          
    • Advanced Data types:

      • Sequence data types:
        • Example-
        • image.png
        • Sometimes it may be possible that some of the keys of sequence will be empty this is known as *sparse sequence
          • image.png
        • Nested sequence:
          • image.png
      • Key-value pairs are known as maps
        • !!map
          
      • Nested mappings:
        • Its nothing but Map within a map
        • image.png
      • Pairs:

        • This is when keys have duplicate values
        • image.png
      • Set:

        • It allows you to have unique values
        • !!set
          
        • Example:
          • names:!!set
            ?kunal
            ?apoorv
            ?rahul
            
      • Dictionary:
        • If you want to represent as entire sequence as value
        • !!omap
          
        • Example:
          • image.png
    • XML: JSON: YAML

      • Lets see how we will convert this into XML, JSON, YAML
      • image.png image.png image.png