YAML Basics
Basic Concept
- YAML is not a Markup Language
- YAML is used to store a variety of information
- It allows us to define key-value pairs like variables, lists, and objects
- YAML is very similar to JSON (Javascript Object Notation)
- Its primary focus is on readability and user friendliness
- YAML is designed to be clean and easily readable
- YAML files can be defined with two different extensions: .yml or .yaml
YAML – Key Value Pairs
- YAML documents consist of key-value pairs.
- The key and value are separated by a colon.
- There must be a space after the colon to differentiate the value.
- YAML supports various data types such as:
- Integer
- Floating-point numbers
- Strings
- Boolean
- Dates (in ISO 8601 format)
- Null values
- Important Note
Name: Dave
Age: 29
Gpa: 4.2
Occupation: Engineer
State: 'New Jersey'
AboutMe: "I am a software engineer"
Male: true
DateOfBith: 1990-09-15T15:53:00
PoliceCases: null
YAML – List / Array
- YAML lists are indented with an opening dash.
- The dash indicates that it’s an element of an array.
- All members of a list begin at the same indentation level, starting with a “-” (a dash and a space).
- Block sequences indicate each entry with a dash and space.
- Flow sequences are written as comma-separated lists within square brackets.
Block Sequence
Persons:
- Dave
- John
- Mike
- Sam
Flow Sequence
Persons: [Dave, John, Mike, Sam]
YAML Dictionary / Map
- YAML dictionaries are sets of properties grouped under an item.
- YAML dictionaries contain key-value pairs.
Dave:
Age: 25
Occupation: Engineer
State: New Jersey
gpa: 4.5
male: true
YAML Lists containing Dictionaries
YAML Lists containing Dictionaries containing Lists
YAML Pipe
- The pipe notation, also known as a literal block.
- All new lines, indentations, and extra spaces are preserved exactly as they are.
Dave:
Age: 25
Address: |
201 A St.
New York 10000
000-111-222
YAML Greater than Sign
- The “greater than” sign notation is also known as a folded block.
- This renders the text as a single line.
- All newline characters are replaced with a single space.
- Blank lines are converted into newline characters.
- We can have comments in YAML with # sign.
Leave a message