# What is YAML?

* YAML is a **data serialization language** for storing information in a human-readable form.
    
* **YAML** stands for "YAML Ain't Markup Language."
    
* YAML is not a Markup Language.
    
* YAML is used to store complex data in a compact and readable format.
    
* YAML was originally designed as a **configuration language** but is now used in various applications.
    
* We can use YAML  to define key and value pairs like variables, lists and objects
    
* YAML is very similar to JSON (Javascript Object Notation) and XML (Extensible Markup Language)
    
* YAML primarily focuses on readability and user-friendliness.
    
* YAML is designed to be clean and easy to read.
    
* We can define YAML files with two different extensions.
    
* `.yml`
    
* `.yaml`
    

## YAML BASICS

* YAML Comments
    
* YAML Key-Value Pairs
    
* YAML Dictionary or Map
    
* YAML Array / Lists
    
* YAML Pipe
    
* YAML Greater than Sign
    
* YAML Document Separator
    

## YAML Comments

* We can have comments in YAML with a `#` sign. Below is an example.
    

```yaml
#YAML Tutorial
#Written by Ram
```

## **YAML – Key-Value Pairs**

* YAML documents will be full of key-value pairs.
    
* Key and Value are separated by a colon.
    
* We must have a space after the colon differentiating the value.
    
* YAML Supports different data types.
    
* `Integer`
    
* `Floating point Numbers`
    
* `Strings`
    
* `Boolean`
    
* `Dates  - Format: ISO 8601`
    
* `Null values`
    
* <mark>Important Note</mark> for Strings: Quote strings when they have special characters like colons :, braces {}, pipes |, brackets \[\]
    

```yaml
#Key Value Pairs
Name: Ram
Age: 22
Gpa: 9.0
Occupation: DevOps Engineer
State: 'Andhra Pradesh [AP]'
AboutMe: "I am a DevOps engineer"
Male: true
DateOfBith: 2001-11-26T15:53:00
PoliceCases: null
```

Strings are a collection of characters that represent a sentence or phrase. You either use `|` to print each string as a new line or `>` to print it as a paragraph.

Strings in YAML do not need to be in double quotes.

```yaml
#DatatTypes Examples
integer: 25
hex: 0x12d4 #evaluates to 4820
octal: 023332 #evaluates to 9946

float: 25.0
exponent: 12.3015e+05 #evaluates to 1230150.0

boolean: Yes
string: "25"

infinity: .inf # evaluates to infinity
neginf: -.Inf #evaluates to negative infinity
not: .NAN #Not a Number
```

### YAML Array / Lists

* YAML List is indented with an opening dash.
    
* Dash indicates that it’s an element of an array.
    
* All members of a list are lines beginning at the same indentation level starting with a ”-” (a dash and a space)
    
* Block Sequence indicates each entry with a dash and space
    
* Flow Sequence is written as a comma-separated list within square brackets
    

```yaml
#Block Sequence
Persons:
  - Ram
  - Bhadra
  - Sravan
  - Ravi
#Flow Sequence
Persons: [Ram, Bhadra, Sravan, Ravi]
```

### YAML Dictionary or Map

* Dictionaries are collections of key-value pairs all nested under the same subgroup. They help to divide data into logical categories for later use.
    
* Dictionaries are defined like mappings in that you enter the dictionary name, a colon, and a space followed by one or more indented key-value pairs.
    

```yaml
person:
  name: Ram
  age: 22
  city: kadapa
```

**YAML lists containing dictionaries containing lists**

```yaml
Persons:
  - Ram:
      Age: 22
      Occupation: DevOps Engineer
      State: London
      Degrees:
        - Bachelors
        - Masters
  - Ravi:
      Age: 22
      Occupation: Developer
      State: California
      Degrees: [Bachelors, Masters] # List with a differnt notation
  - Sravan:
      Age: 23
      Occupation: Cloud Developer
      State: Texas
      Degrees:
       - Masters
```

### **YAML Pipe**

* The pipe notation is also referred to as a literal block.
    
* All new lines, indentation, extra spaces everything preserved as is.
    

```yaml
str: Hello World
data: |
   These
   Newlines
   Are broken up
```

### **YAML Greater than Sign**

* The greater-than-sign notation is also referred to as a folded block.
    
* Renders the text as a single line.
    
* All new lines will be replaced with a single space.
    
* Blank lines are converted to newline characters.
    

```yaml
str: Hello World
data: >
   This text is
   wrapped and is a
   single paragraph
```

### YAML Document Separator

* You can have multiple YAML documents in a single YAML file to make file organization or data parsing easier.
    
* The separation between each document is marked by three dashes (`---`)
    

```yaml
---
person: Ram
Hobbies: cooking
---
player: Ravi
action: cycling
---
```

---

Thanks for reading! I hope you found this helpful and informative.

I'm always happy to connect with fellow tech enthusiasts and answer any questions you may have. Don't forget to follow me for more updates on tech, programming, and more.😄😄

Follow me on LinkedIn to see interesting posts like this : ) [**Linkedin**](https://www.linkedin.com/in/subbaramireddy/)
