What is YAML?

YAML is a recursive acronym for “YAML Ain’t Markup Language!” is a data serialization language which is easily read by ‘humans’. It’s commonly used in configuration files(Not limited to it).

NOTE: JSON, A YAML parser can understand JSON, but a JSON parser can not understand YAML.

The file extension is either .yml or  .yaml.


Now let’s jump to the syntax-

  • Every YAML document starts with 3 hyphens ---
  • Every YAML document ends with 3 dots ...
  • YAML is case-sensitive
  • YAML doesn’t support the use of tabs. It supports spaces
  • Data types of yaml:
    • Sequence:- Lists
    • Scalar:- Numbers
    • Mappings:- Dictionary
  • Comments are made by the hash symbol (#). For example:
    • # This is a comment. You can explain your code here
  • The components of the list is denoted by a hyphen (-)
  • Basic syntax:
    • ---
      CLASS-ROLL: 1519182      # Class Roll-No
      Name: "Nishant Parhi"    # Name of student
      Pass: true               # Statement is true
      6th subject: null        # This is null
  • About dictionaries:
    • How to write dictionaries in 2 ways:
      • # About Me
            name: Nishant Parhi
            Age: 17
            Class: 12
      • ---
        Nishant: {name: Nishant Parhi, age: 17, Class: 12}
  • About lists:
    • All components in a list begin with the indentation level starting with a "- " (a hyphen and a space). For example:
      • ---
        # List of favorite games
            - GTA-5
            - Watch Dogs 2
            - FIFA 18
            - Mario Run
  • About Multi-Line stings
    •  There are two ways to write multi-line strings, using | character and > character.
      • data: |
           I am learning about YML files
           I am finding it interesting
              It is easy to learn
               "You can also learn it"
      • data: >
           This is
           another method
           of writing multi-string
           Blank lines create a
           paragraph break