YAML Basics

Core YAML syntax, indentation rules, maps, lists, and practical validation commands for day-one and day-100 YAML workflows.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Scalars, maps, and sequences

Core YAML building blocks and the examples people search for most.

Simple mapping

Define key-value pairs in YAML.

yamlANYyamlmappingbasics
yaml
name: ExpressYou
plan: premium
active: true

Mappings are the YAML equivalent of objects or dictionaries. Keys should be consistent and human readable.

Simple sequence

Represent ordered lists with dashes.

yamlANYyamlsequencelist
yaml
features:
  - message generator
  - fix this message
  - screenshot to reply

Sequences are the YAML equivalent of arrays or lists.

Nested mapping and list

Combine objects and arrays in one document.

yamlANYyamlnestingindentation
yaml
app:
  name: ExpressYou
  pricing:
    monthly: 7.99
    yearly: 59.99
  tools:
    - coach me
    - message generator

Nested indentation controls structure. Spaces matter; tabs should be avoided.

Nulls, booleans, and numbers

Show common scalar values.

yamlANYyamlscalarstypes
yaml
draft: null
enabled: true
max_retries: 3
price: 7.99

Use plain scalars carefully. YAML has implicit typing rules, so quoting can help avoid ambiguity.

Validate and inspect YAML from the terminal

Practical commands that make YAML easier to work with in local and CI workflows.

Lint a YAML file

Check a file for syntax and style problems.

bashANYyamlyamllintlint
bash
yamllint config.yaml

`yamllint` is a standard first pass for catching indentation, trailing spaces, duplicate keys, and other issues.

Parse YAML with Python

Quickly verify that a YAML file loads successfully.

bashANYyamlpythonvalidation
bash
python - <<'PY'
import yaml
with open('config.yaml') as f:
    print(yaml.safe_load(f))
PY

Useful when you already have Python and PyYAML available and want a fast sanity check.

Pretty-print YAML with yq

Read and normalize YAML output from the command line.

bashANYyamlyqformat
bash
yq '.' config.yaml

Great for validating structure and making machine-generated YAML easier to inspect.

Validate Kubernetes YAML client-side

Check whether a manifest parses before applying it.

bashANYyamlkubernetesvalidation
bash
kubectl apply --dry-run=client -f deployment.yaml

This catches many structural issues in Kubernetes manifests before they hit the cluster.

Recommended next

No recommendations yet.