app:
name: coderstool
env: production
Example: Useful for config files where values are grouped under a parent key.
Gotcha: Indentation is structural. Mixing tabs and spaces will break parsing in many tools.
Use this reference when you need a valid YAML structure for config files, CI pipelines, or deployment manifests. The emphasis is on spacing, shape, and common mistakes.
app:
name: coderstool
env: production
Example: Useful for config files where values are grouped under a parent key.
Gotcha: Indentation is structural. Mixing tabs and spaces will break parsing in many tools.
services:
- api
- worker
- scheduler
Example: A clean format for ordered values such as service names, hosts, or roles.
Gotcha: Each list item needs the same indentation level under the parent key.
users:
- name: Ada
role: admin
- name: Linus
role: maintainer
Example: Useful for deployment config, CI jobs, or any file that stores repeated structured records.
Gotcha: Child properties must line up under the list item they belong to.
message: |
Build finished successfully.
Deploy starts in five minutes.
Example: Use the pipe style when you want to preserve line breaks in notes, templates, or messages.
Gotcha: Use `|` to keep newlines and `>` to fold them. Pick the one that matches how the receiving tool reads text.
retries: 3
enabled: true
Example: Useful when you want config values to remain typed rather than turn into plain strings.
Gotcha: Some YAML parsers are permissive with scalar types. Quote values when you explicitly need string semantics.
YAML is popular because humans can scan it quickly, but that same friendliness hides structural rules that break fast when indentation or nesting drifts. This reference is for the practical side of YAML: writing valid mappings and lists, understanding scalars, and using anchors or aliases when a config repeats itself.
If you searched for yaml examples, yaml sample, YAML syntax, or YAML reference anchor, this page is meant to be the compact answer layer. It explains the pieces you need to write working configuration, not just the formal grammar.
| Structure | Example | Why it matters |
|---|---|---|
| Mapping | name: api | Key-value structure |
| Sequence | - build | Ordered list of items |
| Nested mapping | `database:
host: db` | Groups related settings |
| Sequence of mappings | - name: web | Common in services and pipeline steps |
| String scalar | env: production | Simple text value |
| Boolean scalar | enabled: true | Real boolean, not a string |
| Anchor | defaults: &defaults | Reuse a block elsewhere |
| Alias | <<: *defaults | Merge or reuse anchored values |
```yaml
app:
name: billing-api
port: 8080
features:
database:
host: db.internal
ssl: true
```
This example shows why YAML is appealing for configuration. The shape is readable at a glance. But it is also a reminder that structure is carried by indentation, not braces. Two accidental spaces can change meaning or break the file completely.
YAML is often described informally as “human-friendly,” and that is directionally true. But friendliness is not looseness. Keys and nesting still obey strict structure. Some values that look like plain strings can be interpreted differently by tools depending on schema or parser behavior. That is why many teams quote values when ambiguity would be costly.
A practical YAML reference should keep these points visible:
-key: valueWhen people ask about a YAML reference, they often mean a YAML anchor or alias. Anchors let you name a block, and aliases let you reuse it.
```yaml
defaults: &defaults
retries: 3
timeout: 30
job:
<<: *defaults
timeout: 60
```
This pattern is useful in CI pipelines, deployment manifests, or service definitions where several blocks share the same defaults. It is also a good example of where YAML differs from JSON. YAML can express this kind of reusable structure directly, while plain JSON usually cannot without a higher-level convention.
YAML can represent many of the same data shapes as JSON, but it is not simply relaxed JSON. It has its own syntax, merge features, multiline styles, and parser-specific edge cases. That is why copying JSON habits straight into YAML can create subtle errors. For example, indentation now carries the structure, and anchors introduce reuse patterns that JSON does not natively provide.
This is also why it helps to keep a JSON reference nearby. YAML is excellent for human-edited configs. JSON is excellent when strict machine-oriented structure is the priority.
| Mistake | Why it fails or confuses |
|---|---|
| Inconsistent indentation | The parser reads a different structure than you intended |
| Mixing tabs and spaces | Many tools reject or misread the file |
| Overusing anchors | The config becomes harder to read |
| Forgetting list dashes | A sequence silently turns into a mapping problem |
| Leaving ambiguous scalars unquoted in sensitive contexts | Tooling may interpret the value unexpectedly |
It comes from the recursive name “YAML Ain't Markup Language.” In practical terms, it signals that YAML is meant for data representation, especially human-readable configuration, not document markup.
Start with a simple mapping or list, keep indentation consistent, and only nest when the shape is clear.
An anchor names a block with &name, and an alias reuses it with *name. Some tools also support merge keys like <<: *name.
Use YAML when humans will edit the configuration frequently and readability matters. Use JSON when strict, explicit machine-oriented structure is the priority.
Compare this page with the JSON reference for stricter structured data, the regex reference for pattern matching inside config-like text, the Bash reference when config values are wired into shell scripts, or the VS Code shortcut reference when you edit configuration files heavily inside the editor.
YAML gives you anchors, aliases, multiline forms, and merge patterns, but readability should stay the priority. A short, repeated block is often better than an indirect one that forces the next reader to jump around the file. Use reuse features when they reduce real maintenance cost, not just because the syntax allows them.
Getting information off the Internet is like taking a drink from a fire hydrant.
…
…