YAML :
A YAML file is like any other file which is used to represent configuration data. It define data in key-value pair. The key and value will be separated by a color and a white space(must).
In YAML file we must have to take care of spaces. Otherwise it will throw an syntax error.
# Sample file:
Animal: Dog
Phone: iphone
Laptop: Thinkpad
Array List :
If an element starts with dash(-) it indicates that it is an element of array in yaml file.
# Array List:
Fruits:
- Orange
- Apple
- Banana
Vegetables:
- Carrot
- Potato
- Tomato
Dictionary :
A dictionary is a set of properties grouped together under an item.
We must have equal number of blank spaces before the properties of a single item so that they all are grouped together.
# Dictionary / Map:
Orange:
Calories: 50
Fat: 0.2 mg
Carbs: 20 mg
Mango:
Calories: 60
Fat: 0.3 mg
Carbs: 40 mg
#List and Dictionary together:
Fruits:
- Orange:
Calories: 50
Fat: 0.2 mg
Carbs: 20 mg
- Mango:
Calories: 60
Fat: 0.3 mg
Carbs: 40 mg
Difference between Dictionary and List
dictionary is an un-ordered Collection. while list is an Ordered Collection.
# Dictionary: An un-ordered pair
# Dictionary1
Orange:
Calories: 50
Fat: 0.2 mg
Carbs: 20 mg
# Dictionary2
Orange:
Fat: 0.2 mg
Calories: 50
Carbs: 20 mg
# Dictionary1 = Dictionary2 , Although we have changed the position of element.
# List: An ordered pair
# List1
Fruits:
- Orange
- Apple
- Banana
# List2
Fruits:
- Apple
- Orange
- Banana
# List1 != List2 , Since we have changed the position of element.