The short answer
- YAML is a Unicode-based data serialization language that represents configuration and exchange data as readable text, but loading it requires a processor compatible with its version and tags.
- On Windows or Mac, open a .yaml or .yml file in a text editor to read its contents. On a phone, use a text editor that can access the file. Reading text does not require deserializing it. To load the contents as program data, use a processor supporting the relevant YAML version and tags. Check indentation and syntax when loading fails. A YAML stream can contain multiple documents; an application accepting only one should reject additional documents.
- The high risk concerns unsafe parsing. Tag processing can cause unintended code execution, so deserializers should disable code execution by default and use safe loading. Cyclic references and alias expansion can cause infinite loops or exponential data growth. Validate input and limit anchor recursion depth. Readable text or successful loading does not prove that a file is safe.
YAML files: opening, compatibility and safe parsing
YAML stands for “YAML Ain’t Markup Language.” Its basic structures are mappings, sequences and scalars. Indentation can express hierarchy, colons separate keys and values, and hyphens introduce list items. YAML also supports type tags, anchors and aliases. The registered media type is application/yaml; .yaml is the preferred extension and .yml is also recognized. No fixed magic number is registered.
YAML-to-JSON conversion should not be assumed lossless. Comments, directives and the alias representation may be lost. Non-string keys, cyclic references and types outside JSON need additional handling. Check the converted result against the data you need to preserve.
How to open it
On Windows or Mac, open a .yaml or .yml file in a text editor to read its contents. On a phone, use a text editor that can access the file. Reading text does not require deserializing it. To load the contents as program data, use a processor supporting the relevant YAML version and tags. Check indentation and syntax when loading fails. A YAML stream can contain multiple documents; an application accepting only one should reject additional documents.
On Windows or Mac, open a .yaml or .yml file in a text editor to read its contents. On a phone, use a text editor that can access the file. Reading text does not require deserializing it. To load the contents as program data, use a processor supporting the relevant YAML version and tags. Check indentation and syntax when loading fails. A YAML stream can contain multiple documents; an application accepting only one should reject additional documents.
YAML-to-JSON conversion should not be assumed lossless. Comments, directives and the alias representation may be lost. Non-string keys, cyclic references and types outside JSON need additional handling. Check the converted result against the data you need to preserve.
File safety
The high risk concerns unsafe parsing. Tag processing can cause unintended code execution, so deserializers should disable code execution by default and use safe loading. Cyclic references and alias expansion can cause infinite loops or exponential data growth. Validate input and limit anchor recursion depth. Readable text or successful loading does not prove that a file is safe.
An unknown sender, a name ending in two extensions, or contents that do not match the extension — check before you open it.
Converting it
YAML-to-JSON conversion should not be assumed lossless. Comments, directives and the alias representation may be lost. Non-string keys, cyclic references and types outside JSON need additional handling. Check the converted result against the data you need to preserve.
Convert a copy, never the original, then compare quality, metadata, and layout against what you started with.
Common questions
What is a YAML file used for?
YAML is a human-readable, cross-language data serialization language commonly used for configuration files and data exchange. It represents data using mappings, sequences and scalars.
How do I open YAML files on Windows?
Open the .yaml or .yml file in a text editor to read it. If an application needs to load the data, its YAML processor must support the file’s version and tags.
How do I open YAML files on Mac?
Use a text editor to open the .yaml or .yml file. Text viewing lets you inspect its contents; loading it as data additionally requires a compatible YAML processor.
How do I open YAML files on a phone?
Use a text editor that can access the file on your phone. YAML is plain text, so the editor can display its contents; loading it as data requires a compatible YAML processor.
How do I check YAML indentation and syntax when a file will not load?
Check indentation, key-value separators and list markers with a compatible YAML processor. Loading can also fail because tags cannot be resolved, recognized or constructed. An application accepting one document should reject extra documents.
What are the differences between YAML and YML file extensions?
Both extensions are recognized for YAML. RFC 9512 prefers .yaml and also recognizes .yml. Choosing one extension does not resolve version or tag compatibility problems.
What losses can YAML-to-JSON conversion cause?
Comments, directives and alias representation may be lost. Non-string keys, cyclic references and non-JSON types require additional handling, so conversion is not necessarily lossless.
How can I safely parse untrusted YAML files?
Use safe loading with code execution disabled by default. Validate input and limit anchor recursion depth because tag handling, cyclic references and alias expansion can create risks. These measures do not establish an absolute safety guarantee.
What are the YAML 1.1 and 1.2 boolean differences that affect compatibility?
Implicit boolean interpretation can differ between versions. To reduce compatibility problems, use true or false in the case forms allowed by the YAML 1.2 core schema, and check the receiving processor’s version.
How do YAML anchors and aliases work, and what limits matter?
An anchor marks a node, and an alias refers to an anchored node. Cyclic references or alias expansion can cause infinite loops or exponential data growth, so processors need input validation and limits on anchor recursion depth.
Related formats
Sources
YAML Ain’t Markup Language (YAML) Version 1.2, Revision 1.2.2 · YAML 官方规范 / YAML Language Development Team
RFC 9512: YAML Media Type · IETF / RFC Editor