YAML 1.2 Specification
YAML 1.2 serialization 格式化, 节点 types, tags, 和 JSON 模式分辨率 rules.
Node Types
YAML 1.2 defines three node types: scalar, sequence, and mapping. Scalars are atomic values that may be plain, single-quoted, or double-quoted. Sequences are ordered lists denoted by dashes or square brackets, and mappings are unordered key-value pairs denoted by colons or curly braces. The structure is defined by indentation, which must use spaces consistently within a level.
- scalar
- Atomic value, plain or quoted
- sequence
- Ordered list, block or flow style
- mapping
- Unordered key-value pairs
- anchor/alias
- Reuse nodes with &anchor and *alias
hello or "hello" - a
- b key: value &ref then *ref Tag Resolution
YAML 1.2 resolves plain scalar tags using one of three schemas: the failsafe schema treats everything as strings, the JSON schema matches JSON types, and the core schema extends JSON with additional forms like null and booleans. The core schema is the default and recognizes true, false, null, integers, and floats from plain scalars. Quoting a scalar forces string resolution regardless of content, which is essential for values like version numbers that look like floats.
Security Considerations
YAML allows arbitrary tag resolution and node construction, which enabled dangerous deserialization attacks in some libraries that executed code during loading. YAML 1.2 separates parsing from construction so applications can reject unknown tags. The YAML document must be loaded with a safe loader that ignores or rejects application-specific tags. Never use a general-purpose YAML loader on untrusted input without restricting tag processing.