YAML Configuration Cheatsheet
Quick reference for YAML: syntax, data types, collections, anchors, multiline strings, and common patterns.
| Feature | Description | Example | Category |
|---|---|---|---|
| Key-Value Pair | Basic key-value syntax | name: John Doe age: 30 city: New York | Basics |
| Comments | Single-line comments | # This is a comment name: John # Inline comment | Basics |
| Document Separator | Separate multiple documents | --- doc: 1 --- doc: 2 | Basics |
| Document End | Mark end of document | name: John ... | Basics |
| String | String values (quotes optional) | name: John title: "Lead Developer" quote: 'Single quotes' | Scalars |
| Number | Integer and float values | age: 30 pi: 3.14159 scientific: 1.23e+10 | Scalars |
| Boolean | Boolean true/false values | enabled: true active: false yes_val: yes no_val: no | Scalars |
| Null | Null/empty values | middleName: null empty: ~ nothing: | Scalars |
| Date/Time | Date and timestamp values | date: 2024-01-15 timestamp: 2024-01-15T10:30:00Z | Scalars |
| List (Flow) | Inline list notation | colors: [red, green, blue] numbers: [1, 2, 3, 4] | Collections |
| List (Block) | Block-style list | fruits: - apple - banana - orange | Collections |
| Dictionary (Flow) | Inline dictionary | person: {name: John, age: 30, city: NYC} | Collections |
| Dictionary (Block) | Block-style dictionary | person: name: John age: 30 city: NYC | Collections |
| Nested Collections | Lists and dicts combined | users: - name: John role: admin - name: Jane role: user | Collections |
| Literal Block (|) | Preserve newlines and formatting | description: | This is line 1 This is line 2 Newlines preserved | Multiline |
| Folded Block (>) | Fold newlines into spaces | text: > This long text will be folded into one line | Multiline |
| Literal Chomping | Control trailing newlines | keep: |+ text strip: |- text | Multiline |
| Anchor (&) | Define reusable node | defaults: &defaults timeout: 30 retries: 3 | Anchors |
| Alias (*) | Reference anchored node | dev: <<: *defaults env: development | Anchors |
| Merge Key (<<) | Merge anchored values | base: &base x: 1 child: <<: *base y: 2 | Anchors |
| Multiple Merges | Merge multiple anchors | config: <<: [*defaults, *common] name: app | Anchors |
| Explicit Types | Force data type | number: !!str 123 boolean: !!str true list: !!seq [1, 2, 3] | Advanced |
| Complex Keys | Non-scalar keys | ? [complex, key] : value ? {name: John} : person_data | Advanced |
| Set Type | Unique unordered values | unique: !!set ? item1 ? item2 ? item3 | Advanced |
| Ordered Map | Preserve key order | ordered: !!omap - first: 1 - second: 2 - third: 3 | Advanced |
| Docker Compose | Docker compose example | version: '3.8' services: web: image: nginx:latest ports: - "80:80" | Advanced |
| CI/CD Pipeline | GitHub Actions example | name: CI on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 | Advanced |
| Kubernetes | K8s pod configuration | apiVersion: v1 kind: Pod metadata: name: myapp spec: containers: - name: app image: myapp:1.0 | Advanced |