What is YAML? What does it do?

YAML is an data serialization language. In 2001, YAML meant “Yet Another Markup Language.” The abbreviation was subsequently changed to “YAML Ain’t Markup Language” to underline that the language is proposed for data and not documents.

Note: YAML is not a markup language.

Official definition:

YAML is a human friendly data serialization standard for all programming languages.

File extension of YAML file is .yml. It’s official website is – The Official YAML Web Site

YAML is not a programming language. It records store data, so they do exclude activities and choices.

Dissimilar to XML or JSON, YAML presents information such that makes it simple for a human to understand. The straightforward syntax and structure doesn’t affect the language’s capacities. Any information or structure added to a XML or JSON document can likewise be put in YAML.

What are YAML Features?

  • Consistent data model
  • Easy to implement
  • Easy to read and understand
  • Data portability across the language
  • YAML allows user to add comments
  • No Tabs
  • Good for complex data structure

Basic structure of YAML

Mapping uses colon (:) and space.

name:  Ram
country: India 

YAML supports multiple document

YAML uses three dashes (—) to separate directives from document content.

# Men's all time ODI Ranking
- Viv Richards 
- Joel Garner
- Kapil Dev

# Men's ODI Team Ranking
- England
- India
- New Zealand
- Australia
- South Africa
Note: Indenting is very important in YAML structure

Comments in YAML

User can add comments in YAML file. YAML comments starts with #.

Strike rate:  65    # Strike rate
Average: 52 # Batting average 
highest: 150   # Highest run

Types of YAML structure

There are mainly 2 types of YAML structure –

  • YAML List
  • YAML Map

List Structure

YAML list is just like a sequence of items. It may contains n number of items. An item in YAML List starts with dash (-).

A basic YAML list structure look like this.

- Laptop
- Mobile
- TV

Map structure

YAML maps works with name-value pair similar to JSON.

A valid YAML Map structure look like this –

 product: Laptop
 price: 50000.00

Below is the equivalent JSON structure of above YAML

 "product": "Laptop",
 "price": "50000.00"

What are Nodes in YAML?

A YAML nodes addresses a single data structure. Such nodes have content of one of three types: scalar, sequence, or mapping. Moreover, every node has a tag which serves to confine the set of values the content can have.

What are tags in YAML?

YAML represents type data of native data structures with a basic identifier, called a tag.

How to validate YAML data?

If you want to validate the YAML structure, then go to YAMLlint – The YAML Validator and there you may validate your YAML data.

Is JSON a valid YAML?

YAML 1.2 is the superset of JSON, so a valid JSON file is also a valid YAML file.

Copy a valid JSON data and go to this link – YAMLlint – The YAML Validator

Paste the JSON data and click on Go

Data Types in YAML?

YAML supports all data types such as numbers, strings, arrays. YAML identifies the data type automatically, however users are free to specify the data type.

valueInteger: 50
valuesFloat: 20.0
valueString: "Hello"

Define data type explicitly

You need to include ‘!!’ (double exclamation marks) in order to specify the data types explicitly.

valueInteger: !!int 50
valuesFloat: !!float 20.0
valueString: !!str "Hello"

Keep following https://www.sharepointcafe.net/

Leave a Comment