YAML Specification
repository·main·Indexed 19 days ago
https://github.com/yaml/yaml-specThe official development environment and source for the YAML Data Language Specification, including versions 1.2.0, 1.2.1, and 1.2.2. This repository manages the generation and publishing of the spec.yaml.io website using a Jekyll-based build system and Docker. It contains the primary specification source files in Markdown, YAML, and LaTeX, as well as a glossary covering YAML node types, scalar styles, and the loading and dumping processes.
What's inside yaml-yaml-spec
- This repository contains the YAML 1.2 specification converted from its original HTML format into Markdown. These Markdown sources are intended to be used as the foundation for building new HTML pages for the YAML 1.2 specification (e.g., at https://spec.yaml.io/spec/1.2).
Overview of the YAML Specification Repository
mainThis repository serves as the development environment for the YAML Data Language Specification. It contains the source code and build system used to publish the official YAML 1.2 specification (located in the1.2directory). The repository is used to define and incrementally add components for future versions of the YAML language.Overview of YAML 1.2
mainYAML (YAML Ain’t Markup Language) is a human-friendly, Unicode-based data serialization language. It is designed to represent native data structures from agile programming languages (like Python, Ruby, and JavaScript) using three basic primitives:
- Mappings: Key-value pairs (hashes/dictionaries).
- Sequences: Ordered lists (arrays/lists).
- Scalars: Individual data values (strings, numbers, etc.).
YAML is commonly used for configuration files, log files, interprocess messaging, and object persistence.
Compare YAML flow scalar styles
mainYAML provides three flow scalar styles, each offering a different trade-off between readability and expressive power:
- Double-Quoted (`"..."): Most expressive. Supports arbitrary strings via escape sequences. Best for strings containing special characters or requiring specific control characters (like tabs or newlines).
- Single-Quoted (
'...'): Moderate expressiveness. Supports printable characters. Escaping is limited to doubling single quotes (''). - Plain (unquoted): Most readable, least expressive. No escaping allowed. Highly sensitive to context and restricted by character combinations (like
:or#).
Understand the 1.2.2 YAML Spec source directory layout
mainThe
spec/1.2.2/directory contains the raw source files (Markdown, YAML, and LaTeX) used to generate the published YAML 1.2.2 specification.Key files include:
spec.md: The primary YAML specification source file currently under development.links.yaml: A file used to manage internal link references to keep the main specification file clean.src/: Contains LaTeX source files for generating specification diagram images.ext/: Contains supplemental documentation including:changes.md: Specification changes.errata.md: Specification errata.glossary.md: Specification glossary.resources.md: External community and web resources.team.md: Information about the YAML language development team.
What is YAML and its core design goals?
mainYAML (YAML Ain't Markup Language) is a human-friendly, Unicode-based data serialization language designed to represent native data structures of dynamic programming languages. It is used for configuration, messaging, object persistence, and data auditing.
Its primary design goals, in decreasing priority, are:
- Human readability.
- Portability between programming languages.
- Matching native data structures of dynamic languages.
- Providing a consistent model for generic tools.
- Supporting one-pass processing.
- Expressiveness and extensibility.
- Ease of implementation and use.
Identify YAML Node Kinds
mainEvery node in a YAML representation belongs to one of three kinds:
- Scalar: An opaque datum represented as zero or more Unicode characters.
- Sequence: An ordered series of zero or more nodes. Sequences can contain duplicate nodes or even contain themselves (cycles).
- Mapping: An unordered set of
key: valuenode pairs.- Constraint: Each key in a mapping must be unique.
- Flexibility: Keys can be any arbitrary node, and the same node can be used as a value for multiple keys.
Note: For theoretical and practical purposes, sequences can be viewed as mappings with integer keys starting at zero.
Understand YAML Document structures
mainA YAML stream can contain multiple independent documents. There are three primary types of documents:
- Bare Documents: Contain only content without any directives or markers. The first non-comment line must not start with a
%character. Nodes are indented as if they have a parent at -1 spaces. - Explicit Documents: Begin with a directives end marker (
---) but contain no directives. These can be completely empty. - Directives Documents: Begin with directives (e.g.,
%YAML 1.2) followed by a directives end marker (---).
Documents can be separated by markers to ensure unambiguous parsing, especially when content lines might otherwise look like directives.
# Bare Document Key: Value # Explicit Document --- { matches %: 20 } ... # Directives Document %YAML 1.2 --- !!str "Document" ...- Bare Documents: Contain only content without any directives or markers. The first non-comment line must not start with a
Use Block Scalar Nodes (Literal and Folded)
mainBlock scalars allow multi-line text blocks. They use specific indicators:
|(Literal style): Preserves newlines.>(Folded style): Replaces newlines with spaces.
Node properties (like tags) can span multiple lines and must be indented by at least one more space than the parent block collection.
literal: | value folded: > valueUnderstand the Core Schema in YAML
mainThe Core schema is an extension of the JSON schema designed for more human-readable presentation. It is the recommended default schema for YAML processors. Unlike the JSON schema, if a plain scalar in the Core schema does not match any specific type pattern, it is resolved to a string (tag:yaml.org,2002:str) rather than resulting in an error.Use plain (unquoted) scalar style for maximum readability
mainThe plain style uses no indicators and no escaping. While highly readable, it is the most context-sensitive and restricted style.
Constraints and Rules:
- Whitespace: A plain scalar must not be empty and must not contain leading or trailing whitespace.
- Forbidden Combinations:
- Must never contain the
:(colon followed by space) and#(hash) character combinations (to avoid ambiguity with mappings and comments). - Inside flow collections or when used as implicit keys, they must not contain
[,],{,}, or,.
- Must never contain the
- Starting Characters: Plain scalars must not begin with most indicators. However,
:,?, and-may be used as the first character if they are followed by a non-space "safe" character. - Line Breaks: Long lines can only be broken where a space character is surrounded by non-space characters.
- Implicit Keys: Plain scalars must be restricted to a single line when used as an implicit key.
# Outside flow collection: - ::vector - ": - ()" - Up, up, and away! - -123 - http://example.com/foo#bar # Inside flow collection: - [ ::vector, ": - ()", "Up, up and away!", -123, http://example.com/foo#bar ]Use separation lines and comments between tokens
mainYAML allows tokens to be separated by multi-line (possibly empty) comments. This is useful for organizing large structures.
Constraints
- Implicit Keys: These are restricted to a single line and cannot be separated by multi-line comments.
- Indentation: Even if separation comments are not restricted by indentation, any structures following these comments must be properly indented to maintain valid YAML syntax.
{ first: Sammy, last: Sosa }: # Statistics: hr: 65 avg: 0.278