# YAML  For   DevOps

Hello Every One I am Goutham In this blog I would like to explain what is YAML,

why it is used and how to write some of the representations while writing YAML file.

## YAML

**Yet Another Markup Language** or YAML ain't markup language which emphasizes that YAML is for data, not documents. YAML is a popular programming language because it is designed to be easy to read and understand.So basically YAML is for storing data.

## For what YAML is used

YAML is a digestible data serialization language often used to create configuration files with any programming language. Designed for human interaction, YAML is a strict superset of JSON, another data serialization language. But because it's a strict superset, it can do everything that JSON can and more. Data stored as key value pair in YAML file.

GitHub Actions use YAML file to establish workflows.

**YAML uses strict indentation**

### How to write some of the representations in YAML file

Here I am going to show YAML syntax and its equivalent JSON syntax to understand better.

## Strings

```yaml
fruits: "Mango"   #Space after colon is necessary
```

```json
{
"fruits": "Mango"
}
```

In this syntax key fruits is storing Mango value we can even remove double quotes and can even use single quotes all represents same.

If value contains multiple strings then

```yaml
fruits: |             # Mango , Apple must follow after fruits  
  Mango          # which means Mango ,Apple belongs to fruits key                             
  Apple
```

```json
{
"fruits": "Mango\nApple\n"
}
```

If we want to represent all the following strings as a single string then

```yaml
fruits: >
  Mango
  Fruits
```

```json
{
"fruits": "Mango Fruits\n"
}
```

## Arrays

If we want to represent arrays in YAML then

```yaml
- Apple
- Banana
- Mango
```

```json
[
"Apple", "Banana" ,"Mango"
]
```

### Objects

Objects in YAML can be represented as

```yaml
fruits:
 Apple: Red
 Mango: Yellow
```

```json
{
"fruits":{
"Apple" :"Red",
"Mango": "Yellow"
}
}
```

### Array of Objects

```yaml
fruits:
 - Name: Apple
   color: red
 - Name: Mango
   color: yellow
```

```json
{
 "fruits":[
{
"Name": "Apple",
"color": "red"
},
{
"Name": "Mango",
"color": "yellow"
}
]
}
```

Finally, Let's try to combine everything we have learned let us display 2 students information like RollNo, name, address, Marks in 2 subjects

```yaml
 Goutham:
     RollNo: 1

     address: >
      M J Colony
      Balaji Nagar
       Kukatpally, Hyderabad
     Marks:
     - maths: 90
       phy : 80
      
 Akhil :
      RollNo: 2
      address: >
       Plot no 35.Indwell 
       house, Kavuri Hills Phase 3,
       Madhapur,Hyderabad
      Marks:
       - maths: 89
         phy : 90
```

```json
{
   "Goutham": {
      "RollNo": 1,
      "address": "M J Colony Balaji Nagar Kukatpally, Hyderabad\n",
      "Marks": [
         {
            "maths": 90,
            "phy": 80
         }
      ]
   },
   "Akhil": {
      "RollNo": 2,
      "address": "Plot no 35.Indwell  house, Kavuri Hills Phase 3, Madhapur,Hyderabad\n",
      "Marks": [
         {
            "maths": 89,
            "phy": 90
         }
      ]
   }
}
```

That's it about what I want to explain YAML in my own words. I am a beginner to DevOps recently started learning it If you find any thing wrong please let me know.

Thanks for reading my blog have a nice day 🎉🎉🎉.
