1---
2name: yaml
3description: Write valid YAML that parses predictably across languages and versions.
4metadata:
5 source: https://skillmd.com/skills/modbender/yaml
6 clawdbot:
7 emoji: 📋
8 os:
9 - linux
10 - darwin
11 - win32
12---
13
14## Type Coercion Traps
15
16- `yes`, `no`, `on`, `off`, `true`, `false` → boolean; quote if literal string: `"yes"`
17- `NO` (Norway country code) → false in YAML 1.1; always quote country codes
18- `1.0` → float, `1` → int; quote version numbers: `"1.0"`
19- `010` → octal (8) in YAML 1.1; quote or use `0o10` explicitly
20- `null`, `~`, empty value → null; quote if literal: `"null"`, `"~"`
21- `.inf`, `-.inf`, `.nan` → special floats; quote if literal strings
22
23## Indentation
24
25- Spaces only—tabs are forbidden and cause parse errors
26- Consistent indent width required within document—2 spaces conventional
27- Sequence items `-` count as indentation—nested content aligns after the space
28
29## Strings
30
31- Colon followed by space `: ` triggers key-value—quote strings containing `: `
32- `#` starts comment unless quoted—quote strings with `#`
33- Leading/trailing spaces stripped from unquoted strings—quote to preserve
34- Quote strings starting with `@`, `` ` ``, `*`, `&`, `!`, `|`, `>`, `{`, `[`, `%`
35
36## Multiline Strings
37
38- `|` literal block preserves newlines; `>` folded block joins lines with spaces
39- Trailing newline: `|-` and `>-` strip final newline; `|+` and `>+` keep trailing blank lines
40- Indentation of first content line sets the block indent—be consistent
41
42## Structure
43
44- Duplicate keys: YAML spec says last wins, but some parsers error—avoid duplicates
45- Anchors `&name` and aliases `*name` reduce repetition—but aliases can't override anchor values
46- Document separator `---` starts new document; `...` ends document—useful in streams
47- Empty documents between `---` markers are valid but often unintended
48
49## Comments
50
51- `#` only valid at line start or after whitespace—`key:value#comment` has no comment
52- No inline comments after multiline block scalars—comment applies to next line
53- No multi-line comment syntax—each line needs `#`
54
55## Compatibility
56
57- YAML 1.1 vs 1.2: boolean words (`yes`/`no`), octal syntax differ—know which version parser uses
58- JSON is valid YAML 1.2—but YAML features (anchors, multiline) don't round-trip to JSON
59- Some parsers limit nesting depth or file size—test with expected data scale