64 lines
No EOL
1.4 KiB
Markdown
64 lines
No EOL
1.4 KiB
Markdown
---
|
|
obj: format
|
|
website: https://yaml.org
|
|
wiki: https://en.wikipedia.org/wiki/YAML
|
|
mime: "application/yaml"
|
|
extension: ["yaml", "yml"]
|
|
---
|
|
|
|
# YAML
|
|
YAML is a data serialization language designed to be human-friendly and work well with modern programming languages for common everyday tasks. Additionally any valid [JSON](JSON.md) document is also a valid YAML document.
|
|
|
|
## Syntax
|
|
### **Indentation:**
|
|
Indentation is used to represent the structure of the data. Spaces or tabs can be used, but consistency is crucial.
|
|
|
|
### **Key-Value Pairs:**
|
|
Data is represented as key-value pairs using a colon (`:`) to separate the key and value.
|
|
|
|
### **Comments:**
|
|
Comments can be made with `#` symbol.
|
|
|
|
```yaml
|
|
key: value # My Comment
|
|
# Another comment
|
|
```
|
|
|
|
### **Lists / Sequences:**
|
|
Lists are represented using a hyphen (`-`) followed by a space.
|
|
```yaml
|
|
key: value
|
|
list:
|
|
- item1
|
|
- item2
|
|
```
|
|
|
|
### **Mappings:**
|
|
Mappings represent key-value pairs.
|
|
|
|
```yaml
|
|
key: value
|
|
nested:
|
|
key: value
|
|
```
|
|
|
|
### Data Types
|
|
YAML support many different data types such as strings, numbers and booleans.
|
|
|
|
```yaml
|
|
mystr: "Hello World"
|
|
mynum: 3
|
|
myfloat: 3.1415
|
|
mybool: true
|
|
multiline: |
|
|
hello world
|
|
this is multiline
|
|
key: value
|
|
```
|
|
|
|
## Common Use Cases
|
|
### 1. **Configuration Files:**
|
|
YAML is widely used for configuration files in applications and systems.
|
|
|
|
### 3. **CI/CD Pipelines:**
|
|
Many CI/CD tools, such as GitLab CI and [GitHub Actions](../dev/GitHub%20Actions.md), use YAML for defining pipelines. |