Zum Inhalt springen
uencoder

YAML 1.2-Spezifikation

YAML 1.2 serialization formatieren, node Typen, Tags, und JSON Schema resolution Regeln.

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
hello or "hello"
sequence
Ordered list, block or flow style
- a
- b
mapping
Unordered key-value pairs
key: value
anchor/alias
Reuse nodes with &anchor and *alias
&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.

Verwandte Tools

参考链接