YAML Cheat Sheet

Skim the syntax map, drop a snippet into the playground, and fix indentation before a pipeline chokes on a stray tab. Validation and formatting run in your tab, not on a server.

Hands-on

Paste, validate, format

Press Ctrl + Enter to validate after you type.

Your YAML never leaves the browser. Use this strip to rehearse manifests before you paste them into GitHub Actions or a cluster.

Enter YAML to validate or format.

Waiting for input

Syntax atlas

Open a tile when you need a reminder. Each block mirrors what parsers expect in the wild.

Scalars, booleans, and null
title: Plain string version: "1.4.2" enabled: true owner: ~
Strings
Quotes matter when you need escapes, colons, or leading spaces.
Booleans
Stick to lowercase true and false so you do not surprise a language binding.
Null
null and tilde both read as empty.
Sequences
steps: - checkout - run: npm ci - run: npm test

Dash lines must line up with the key they belong to. Drift one space and the tree breaks.

Mappings and nesting
deploy: region: us-east-1 autoscale: min: 2 max: 10
Two-space rhythmColon plus space
Comments and guardrails
# Rotate weekly token: ${VAULT_TOKEN}
Comments
Hash to end of line. JSON does not give you this, which is why teams pick YAML for configs.
Tabs
Spec says no. Editors hide them. Parsers do not.

The failure mode nobody reads until 2 a.m.

Indentation is the silent killer. A pipeline log shows a vague parse error while your file looks fine in the editor because invisible whitespace changed. This page exists so you rehearse structure before you merge.

YAML trades braces for whitespace. You read fewer symbols, yet one sloppy paste from a chat window still misaligns a tree.

What the playground checks (and skips)

The checker spots tabs, uneven spacing, and quotes left open. The playground never runs your file against a live schema, so a Kubernetes manifest still needs kubectl or a cluster dry run before you call production safe.

For a deeper tidy pass after you fix syntax, pair this page with the YAML beautifier when you want consistent wrapping across a large file.

Editorial note: We treat unknown YAML from the internet as hostile. Paste samples into this sandbox first, read them, then move only what you trust into a repo.

YAML beside JSON on the same team

TopicYAMLJSON
CommentsYes, with #No
Trailing commasNot allowedNot allowed
Readable configsStrong fitNoisy for humans

When you bounce between formats, keep the JSON cheat sheet nearby so you do not mix rules.

Where YAML shows up in shipping software

  • GitHub Actions and GitLab CI workflows
  • Docker Compose stacks on a laptop
  • Kubernetes objects before kubectl apply
  • Ansible inventories when you automate hosts

Each tool adds extra keys. The grammar on this page is the shared floor. The schema is the ceiling.

Block scalars when a single line is not enough

Long certificates, SQL, and markdown blocks belong in literal or folded scalars. A pipe keeps newline characters so your shell script keeps every line break. A greater-than folds soft breaks into spaces, which helps prose but surprises people who expected hard wraps.

Indent the content one level deeper than the key, or parsers treat the next line as a sibling node. If you copy from a wiki, re-indent before you validate.

Anchors, aliases, and merge keys

YAML lets you stamp an anchor on a mapping, reuse an alias elsewhere, and merge defaults with a merge key. Power users love the brevity. Reviewers hate hunting hidden inheritance during an outage.

We do not highlight anchors in the playground tiles above because many CI templates forbid them outright. If your org allows them, keep depth shallow and name anchors like you name functions.

When the parser disagrees with your editor theme

Most pain arrives from mixing YAML 1.1 and 1.2 rules around booleans and sexagesimal numbers. A bare yes or no might parse as boolean in one runtime and as a string in another. Quoting removes the ambiguity at the cost of noise.

Version pins matter for Ruby, Python, and Go loaders. Pin the parser in your service the same way you pin dependencies, then lint configs in CI so drift shows up as a failed build instead of a silent cast.

Stop shipping secrets in plain YAML

Files are easy to grep. Store tokens in a vault or secret manager, reference them with environment injection, and keep samples redacted. The playground never stores your paste, yet a committed file lasts forever in git history.

Workflow tip from teams who review a lot of diffs

Load the sample, break a dash on purpose, validate, then undo. You build muscle memory for how errors read. When you edit long term in Vim, the Vim cheat sheet still saves time on bulk indent shifts.

Red flags worth a second glance

Duplicate keys in one mapping should fail fast, yet some loaders pick the last winner quietly. Environment-specific files often repeat keys by accident after a bad merge. Run a structural diff, not only a text diff, before you promote a branch.

Large files become slow in browser tools. Split responsibilities across files when your platform supports includes, or trim unused keys so reviewers see signal. The playground handles everyday snippets. Multi-megabyte dumps belong in offline linters.

Unicode looks innocent until invisible direction marks sneak in from a PDF. Re-type critical keys if you suspect copy damage, or normalize through an editor command before you validate.

Need front-end context next? Scan the JavaScript cheat sheet for parsing patterns, or the CSS selector cheat sheet when your YAML drives a static site generator.

YAML playground questions

Short answers about validation limits, privacy, and how this sheet differs from a cluster dry run.

Does validation mean my Kubernetes file will apply cleanly?

No. The playground checks basic syntax such as tabs, quotes, and spacing. A cluster still enforces apiVersion, required keys, and policy. Use kubectl --dry-run=client or your platform validator before you rely on the result.

Where does my YAML go when I click Validate?

Nowhere off-device. Parsing runs in the browser tab you have open. Close the tab and the text is gone unless your browser keeps drafts.

Why does Format sometimes look different from my team style guide?

The formatter normalizes spacing in a simple way. Expect a light tidy pass, not a full prettier or schema-aware rewrite. For strict org rules, run your internal formatter after you fix syntax here.

How is this different from the YAML beautifier tool?

This page mixes a syntax atlas with a quick checker. The beautifier focuses on polishing full files. Use whichever matches the task, or chain them.

Should pasted YAML from a random gist get a second read?

Treat unknown text like code. Read every line, validate here for structure, and avoid running shell hooks or includes you do not understand. Secrets belong in vaults, not in samples.

What breaks most often in real repos?

Tabs mixed with spaces, lists indented under the wrong parent key, and unquoted strings with colons inside. Validate early and keep two-space indents consistent.