YAML Introduction (original) (raw)
Last Updated : 1 Apr, 2026
YAML (YAML Ain’t Markup Language) is a human-readable data serialization language used to store and exchange data. It is commonly used for configuration files and data representation.
- Easy to read and write (uses indentation, no brackets)
- Widely used in DevOps tools (Docker, Kubernetes, Ansible)
- Supports structured data (lists, key-value pairs)
- Used for configuration and data exchange
YAML uses simple structures like key-value pairs and lists.
**Example:
name: John age: 25 skills:
- Java
- Python
- DevOps
- **name, age: keys
- **John, 25: values
- **- : represents list items
- Indentation defines hierarchy
Features of YAML
- Provides cross-language portability of data
- Supports efficient one-pass processing
- Offers a consistent and flexible data model
- Easy to use and implement in applications
YAML File Extensions
YAML files are saved with a file format that ends with either ".yaml" or ".yml"
**Example: The visual studio code provides the option to save the file as .yaml extension.
.webp)
Visual studio code - save file as .YAML.
Rules of YAML
1. Uses spaces for indentation (not tabs)
- YAML uses spaces to define structure and hierarchy
- Tabs are not allowed and can cause errors
2. Structure is defined by indentation
- Indentation determines parent-child relationships
- Proper alignment is required to maintain data structure
3. Uses : for key-value pairs
- Colon separates keys and their values
- A space is required after : for correct syntax
4. Lists start with -
- Hyphen (-) is used to represent list items
- Each item should be properly indented under the list
- # is used to write comments in YAML
- Comments are ignored during execution
YAML Scalar
A YAML scalar is a single value that represents basic data such as a string, number, boolean, or null. It is the simplest data type in YAML and does not contain any nested structure like lists or mappings.
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
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.
key: 'value'
3. Double-Quoted Style:
- Double-quoted style in YAML allows strings to include escape sequences (like \n, \t) that are interpreted during processing.
key: "value with\nnewline"
4. Flow Style:
- Flow style in YAML allows data to be written in a compact, inline format using braces {} for maps and brackets [] for lists.
key: { foo: bar, baz: 42 }
Creating a YAML File
There are mainly three ways to create a YAML file:
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: or 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.
Method 2: Create a file using the YAML URL:
This method allows you to create a YAML file by accessing a YAML file directly through a URL. It is useful for downloading, referencing, or using configuration files hosted online.
**Example:
https://github.com/kishan-kaushik/git-project/blob/master/file.yaml
Method 3. Create the YAML file using YAML Template:
This method allows you to create a YAML file using a predefined template structure. It helps in quickly generating configuration files with standard formatting and required fields.
**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
Advanced Features in YAML
1. Tabs
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.
2. Whitespace
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 #.
3. Explicit Data Types
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.
4. Multi-document support
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
5. 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.
