DEV Community

jainnehaa
jainnehaa

Posted on

Quick Guide to YAML

YAML is a data serialization format and processing model, used extensively for log files, Internet messaging, filtering and can be used in conjunction with other programming languages.
In computing, serialization is the process of translating a data structure or object state into a format that can be stored or transmitted and reconstructed later possibly in a different computer environment. XML, JSON, BSON, YAML, MessagePack, protobuf are some commonly used data serialization formats.
YAML is a superset of JSON, so JSON files are valid in YAML.
YAML stands for 'Yet Another Markup Language' or 'YAML Ain’t Markup Language', which emphasizes that YAML is for data and not documents.
YAML files can be added to source control, such as Github, so that changes can be tracked and audited.

YAML uses indentation to indicate nesting. Tab characters are not allowed, so whitespaces are used instead. There are no usual format symbols, such as braces, square brackets, closing tags, or quotation marks. YAML files use a .yml or .yaml extension.
The structure of a YAML file is a map or a list. It also contains scalars, which are arbitrary data encoded in Unicode, that can be used as values such as strings, integers, dates, numbers, or booleans.

YAML parser is used to read YAML documents and provide access to their content and structure.
YAML emitter is used to write YAML documents, serializing their content and structure.
YAML processor is a module that provides parser or emitter functionality or both.

YAML Syntax Example :

---
# An employee record
name: Martin D'vloper
job: Developer
skill: Elite
employed: True
foods:
  - Apple
  - Orange
  - Strawberry
  - Mango
languages:
  perl: Elite
  python: Elite
  pascal: Lame
education: |
  4 GCSEs
  3 A-Levels
  BSc in the Internet of Things
Enter fullscreen mode Exit fullscreen mode

Three dashes indicate start of a new YAML document. YAML supports multiple documents and compliant parsers will recognize each set of dashes as the beginning of a new one. The construct that makes up most of a typical YAML document is a key-value pair.
YAML supports nesting of key-values, and mixing types.

YAML has been criticized for its significant whitespace, confusing features, insecure defaults, and its complex and ambiguous specification.
Configuration files can execute commands or load contents without the users realizing it. Editing large YAML files is difficult, as indentation errors can go unnoticed. Truncated files are often interpreted as valid YAML due to the absence of terminators.

The perceived flaws and complexity of YAML has led to the emergence of stricter alternatives such as StrictYAML and NestedText.

References :
Redhat
yaml.org
yaml.org
wiki
blogs

Top comments (0)