Cheat Sheets Development

YAML Syntax Cheat Sheet

Quick reference for YAML: scalars, strings, lists, mappings, multi-line text, anchors, multiple documents and the values that parse differently than you expect.

Last reviewed:

AdSense Placeholder
Slot: header_reference_page
On this page

YAML is an indentation-based data format that expresses the same structures as JSON. Spaces mark nesting (never tabs), # starts a comment, and every JSON document is also valid YAML. Check any file with the YAML Validator, and convert with the YAML to JSON Converter or JSON to YAML Converter. The results below were produced by running the snippets through a YAML 1.1 parser.

Scalars

Strings need quotes only when they would otherwise be read as another type or contain special characters such as : or #.

YAML text Parsed as
42 42
3.14 3.14
true true
null null
~ null
"42" "42"
2026-10-27 date 2026-10-27
0o14 "0o14"

Lists and mappings

Lists use - per item (block style) or [a, b] (flow style). Mappings use key: value or {k: v}. Indent with spaces; keep the width consistent.

fruits:
  - apple
  - banana
  - cherry
short: [1, 2, 3]
server:
  host: localhost
  port: 8080
  tags: {env: dev, debug: true}

Parsed: {"fruits": ["apple", "banana", "cherry"], "short": [1, 2, 3]} and {"server": {"host": "localhost", "port": 8080, "tags": {"env": "dev", "debug": true}}}.

Multi-line strings

| keeps line breaks as written; > folds line breaks into spaces. The trailing newline is kept by default.

literal: |
  line one
  line two
folded: >
  line one
  line two

Parsed: {"literal": "line one\nline two\n", "folded": "line one line two\n"}.

Anchors, aliases and merge

&name defines an anchor, *name reuses it and <<: *name merges a mapping into another. The merge key is supported by many but not all parsers.

base: &base
  retries: 3
  timeout: 30
prod:
  <<: *base
  timeout: 60

Parsed: {"base": {"retries": 3, "timeout": 30}, "prod": {"retries": 3, "timeout": 60}}.

Multiple documents and comments

Separate documents in one file with ---; end with ... if needed. Comments start with # and run to the end of the line.

---
name: one
---
name: two

Gotchas

Different YAML versions read some plain values differently. YAML 1.1 treats yes, no, on and off as booleans and a leading zero as octal; YAML 1.2 does not. Quote any value that must stay a string.

Value Parsed by a YAML 1.1 parser
no false
yes true
on true
NO false
off false
010 8
1_000 1000
1e3 "1e3"
0x1F 31
"no" "no"

Try these tools

See also

  • Comparison JSON vs YAML vs XML
    JSON for APIs and data exchange, YAML for hand-edited configuration, XML for documents and schema-heavy standards.
  • Guide How JSON Works
    The six JSON value types, why parsing fails, traps with big integers and key order, JSONPath queries and converting JSON to TypeScript.
  • Glossary YAML
    YAML is a human-friendly data format that uses indentation instead of brackets, popular for configuration files.
  • Glossary JSON
    JSON (JavaScript Object Notation) is a lightweight text format for structured data, built from objects, arrays, strings, numbers, true.
AdSense Placeholder
Slot: footer_leaderboard