knowledge/technology/files/YAML.md

64 lines
1.4 KiB
Markdown
Raw Normal View History

2023-12-04 10:02:23 +00:00
---
2024-03-06 12:15:41 +00:00
obj: format
2023-12-04 10:02:23 +00:00
website: https://yaml.org
wiki: https://en.wikipedia.org/wiki/YAML
2024-03-06 12:15:41 +00:00
mime: "application/yaml"
extension: ["yaml", "yml"]
2023-12-04 10:02:23 +00:00
---
# 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:**
2024-01-17 08:00:45 +00:00
Many CI/CD tools, such as GitLab CI and [GitHub Actions](../dev/GitHub%20Actions.md), use YAML for defining pipelines.