Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App
Next Article:
What Type of Language is YAML?
Next article icon

What Type of Language is YAML?

Last Updated : 29 Jan, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

As we know the world of technology is filled with various modern and old languages which keep changing from time to time, each one of these languages serves a specific purpose and thus each language is used for performing certain tasks only. But when it comes to the programming language called YAML people sometimes get confused because they have trouble understanding what type of programming language YAML is, so in this article, we will understand what type of language the YAML programming language is.

Introduction

The YAML is an open-source language used for writing configuration files on your system, what makes the YAML language different from other computer languages is that it is human-readable, unlike other programming languages which makes it easier to work with.

yaml-banner
What Type of Language is YAML?

What is YAML?

The full form of the YAML language can be different depending on whom you are asking it, mostly there are two full forms of this language and both of them are considered to be correct, the first one is yet another markup language while the other full form is YAML ain't markup language. if you read the second full form of YAML, you will understand that the YAML is not a markup language which means that this language is used for data and not documents.

YAML syntax:

The syntax of the YAML programming language is very easy to understand and time efficient because it focuses on generating human-readable codes, here are some of the syntax rules for YAML:

Indentation: Just like python, the YAML language also heavily works on the basis of indentation in order to represent the nesting of the data as well as the hierarchy of it.

Note: In YAML, spaces are used for indentation rather than tabs.

Lists: YAML also allows us to create lists if we want, in YAML the lists are based on arrays which are a sequence of items. In YAML, each item which begins with a dash ('-') along with a space is known as a list.

For example:

“`yaml
hobbies:
Catering
Cooking
Coding
“`


Key-Value pair: This contains data which is stored in key value pairs and are separated by a colon.

Example:

"name:Kishan Kaushik"


File Extension: YAML files are saved with a file format that ends with either ".yaml" or ".yml"

As you can see in the image below, the visual studio code provides the option to save the file as .yaml extension.

yaml01-(1)
Visual studio code - save file as .YAML.

YAML Scalar syntax:

YAML scalar means that a simple value for any key, as we discussed later that the scalar can be float, Boolean, integer etc..The scalars are known to be the basic blocks that are required for writing the YAML language and they can be complex as well as simple depending on the requirements. The scalars can be written in various possible ways, let's look at some of them as example:

1. Plain Style:

In the plain style of scalars in YAML, the scalars can be some simple strings which does not include any special characters or quotes, for example you can see:

key: value

2. Single-Quoted Style:

The scalars can also be closed in the single quotes this style is mostly used whenever you want to specify a string just the way it is without any special characters, for example:

key: 'value'

3. Double-Quoted Style:

Just like the single quotation marks we can also use the double quotations for the strings the only difference here is that the double-quoted string allows escape sequence to be interpreted, for example:

key: "value with\nnewline"

4. Flow Style:

Scalars can also be written in a more compact flow of style. this is suited for simple values and short values, for example:

key: { foo: bar, baz: 42 }

XML VS JSON VS YAML - What's The Difference?

All the above three languages are very popular data serialization languages used in the today's industry for computer science and IT development, but which among them is better? and what is exactly the difference between each of them? for answering these questions we will have to take a look at the difference between these languages.

So let's look at the table below which differentiates the XML, JSON and YAML language:

XML

JSON

YAML

XML stands for eXtensible Markup Language.

JSON stands for JavaScript Object Notation.

YAML stands for YAML Ain't Markup Language.

XML is a markup language.

JSON is a data format.

YAML is a data format.

JSON has no concept of comments.

XML allows you to add comments but only within a document.

YAML is designed to make more readable content and thus allows comments.

The XML language supports some complex data types such as charts or images.

Unlike XML, JSON supports only strings, numbers, arrays, boolean, and objects.

YAML can support data types such as date as well as time stamps, sequences, nested, recursive values or primitive data types.

It is somewhat difficult to read or interpret the data if you are using XML.

It is somewhat easier to easy to interpret data in JSON format.

It is much more easier to read the data in YAML than in JSON format.

XML is used for data interchange.

JSON is used better as a serialization format.

YAML is used and suited best only for configuration.

XML is considered to be bulky and somewhat slow in parsing.

The JSON files are smaller compared to the XML file and thus quickly parsed by the JavaScript engine.

YAML is considered as a superset of JSON so it also can deliver a faster data transmission.

What Type of Language is YAML?

Now let's come back to our main question, what type of language is YAML? the YAML inherits the "ML" from the HTML and SGML languages which are known to be markup languages but the YAML itself is not a markup language because it is a unicode based data serialization language.

The main reason for YAML not being a markup language is because the data model of the YAML language only contains tree structure and when we look underneath we will not see any linear text that the tree applies to, because there is nothing to mark up in it.

Features and basic rules of YAML:

There are some basic rules that you must follow whenever you are writing the YAML, those rules are the following:

  • The file must have .yaml as the format or extension while being saved.
  • The YAML language is case sensitive.
  • The YAML language does not provide you with the ability to use tabs whenever you are creating YAML files but you can however you the spaces instead of tabs.

Whenever you are writing using the YAML language then you must follow these rules mentioned above so that you don't encounter any errors.

Features of YAML:

As we have already discussed that the YAML provides us with human readable code which is a feature in itself but let's look at a few features that the YAML language provides which makes it better suited language that it's competitors:

  1. It provides us the ability for cross-language portability of data.
  2. It provides us with a one-pass processing.
  3. The YAML language can provide a data model that is very consistent.
  4. YAML language provides us the ease for use as well as implementation of the code.

How to create a YAML file?

It is very easy and simple to create a YAML file, there are mainly three ways to create a YAML file if you want, let's see what those ways are and also understand each method one by one.

Method 1: Use Any Online Tool for YAML or Text Editor:

Step 1: Use any online tool that helps you to convert the code into indented YAML data,

Step 2: for example we have the following data that we will use for conversion:

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80

Step 3: Then simply go to any online converter website for YAML, for example I have this website that can do so:

https://jsonformatter.org/yaml-parser

Step 4: This will give you the YAML code and then you can download the YAML file as well by using the download button.

yaml-parser
YAML Parser.

Method 2: Create a file using the YAML URL:

As you know that some developers also work with data and file that are stored on the cloud servers and almost 90% of the data is hosted mostly on the Azure, Google Cloud, DigitalOcean etc. so developers can simply use the remote URL to save and edit the YAML files that are stored in the servers.

Here is a sample of the YAML URL. Now you can simply click on these YAML sample to view it.

https://github.com/kishan-kaushik/git-project/blob/master/file.yaml

Method 3. Create the YAML file using YAML Template:

YAML is used for configuration files which means that we need to avoid most of the mistakes for this you always need to take precaution and use the right template, for example:

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80

Multi-document support in YAML:

YAML itself doesn't inherently support multi-document structures like JSON arrays or objects. YAML is primarily designed to represent a single data structure. However, there is a way to handle multiple documents within a single YAML file using the --- document separator.

# Document 1
key1: value1
key2: value2

---
# Document 2
key3: value3
key4: value4

As you can see that we have used "---" serves as a document separator.

Indentation in YAML:

YAML uses the indentation in order to indicate both the structure as well as the hierarchy of the data. the recommended indentation for the YAML language files is simply two spaces per level but apart from that YAML can also follow any of the indentation which the individual file uses.

New-Project
indentation in YAML.

Tabs in YAML:

The YAML language does not allow the using of the TAB button because of indentation issues. You can however use any amount of spaces and combination of space instead of using the tabs in the YAML language.

Whitespace in YAML:

YAML is a language that is known to be whitespace-sensitive which means that while indentation defines the structure. however it does not accept any tabs as we discovered earlier for the indentation. so that means that the empty lines are ignored and comments are written using octothorpe #.

Why use YAML instead of JSON?

Many people also ask the question, that why should we use the YAML instead of using JSON, one of the most easiest and simplest way to answer this is because the syntax of YAML is very easy to read, understand and write as compared to JSON, which makes it very easy to write and understand not only for the developers but also the other non-developer members of the team.

Explicit data types in YAML:

In the YAML language, custom data types are allowed but the YAML language is known to natively encode the scalars, if you are wondering what scalars are then simply know that strings, float values, strings are known to be scalars.

Conclusion

In conclusion, we learnt that the YAML language is a data serialization language and not a markup language, apart from that we also looked at why we should use the YAML language instead of using JSON language as well. you can use the YAML language if you want to write simple-to-understand codes for your configuration files.


Next Article
What Type of Language is YAML?

K

kishankaushik
Improve
Article Tags :
  • Linux-Unix
  • Geeks Premier League
  • Geeks Premier League 2023

Similar Reads

    What is Machine Language?
    Machine language is a low-level programming language that is understood by computers. Machine language is made up of binary bits 0 and 1. Machine language is also known as machine codes or object code. As machine language consists of only 0 and 1, that's why it is difficult to understand in raw form
    4 min read
    What is Procedural Language?
    Procedural programming is a software development method that is executed step by step in a certain manner. The sequence of tasks to be carried out in order to find a solution is of primary importance. Procedural languages are encoded as algorithms, so that, in addition, the programmer not only speci
    5 min read
    What Is YAML In Kubernetes ?
    Kubernetes is dependent on YAML (YAML Ain't Markup Language) as its configuration language. YAML makes managing and deploying Kubernetes more easy and simple. In this article, we'll cover all the aspects of using YAML in Kubernetes. Understanding YAMLYAML is a human-readable format of data serializa
    7 min read
    What does {{ }} mean in YAML?
    YAML (YAML Ain't Markup Language) is a popular human-readable data serialization format often used for configuration files and data exchange. YAML's simplicity and readability have made it a favorite among developers and system administrators. While YAML is generally straightforward, there are times
    5 min read
    Why Python is a High Level Language
    Python is categorized as a high-level programming language because of several key characteristics and features that distinguish it from lower-level languages ​​such as assembly language or machine code. In this article, we will see why Python is a high-level language. What Does High-Level Language M
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences