YAML

What is YAML?

YAML, which stands for “YAML Ain't Markup Language,” is a human-readable data serialization standard that can be used in conjunction with all programming languages and is often used to write configuration files. YAML is designed to be clear and understandable by humans, while also being easy to parse and generate by computers.

The syntax of YAML relies on indentation (spaces or tabs) for structure rather than markups like HTML tags. This makes it visually less cluttered compared to other data serialization formats such as XML or JSON. Here are some key features of YAML:

  1. Human-readable: YAML is designed to be easily readable by humans, which allows for easier debugging and editing. It uses a plain text format with minimal punctuation.
  2. Indentation-based nesting: Blocks in YAML are defined through indentation levels, similar to Python or Lua code blocks. This helps create clear hierarchical structures without using additional characters like brackets or braces.
  3. Comments: YAML supports comments by starting a line with the `#` symbol. Comments can be placed on their own lines or inline at the end of a statement.
  4. Data types and structures: YAML supports various data types, including strings, numbers, lists (arrays), and mappings (hashes). It also allows for nested data structures to represent complex hierarchies.
  5. Scalars and collections: Scalar values are single items of data like strings or integers. Collections include sequences (lists) and mappings (key-value pairs).
  6. Tags and anchors/aliases: YAML allows for the use of tags to specify a specific type, such as `!!str` for strings or `!!int` for integers. Anchors (`&`) can be used to define reusable elements in a document, while aliases (`*`) refer to these anchored values.
  7. Multiple documents: A single YAML file can contain multiple YAML documents separated by `—`. Each document is independent of the others and can have its own headers.
  8. DEFAULT VALUE TAGS: You can use tags like `&default_value` to create a default value that can be reused across different parts of your YAML content using aliases, for example, `*&default_value`.

Here's an example YAML document: ```yaml # Comment explaining the structure version: ' - - 0' author: > # Multiline string with a heredoc-style comment

John Doe

— settings:

theme: dark
font_size: "14px"
notifications_enabled: true # Boolean value in YAML is represented as either `true` or `false`.

``` In this example, the document contains a version string, an author name (as a multiline string), and a nested collection of settings. Each setting has its own key-value pair. Comments are used to explain the structure and purpose of each section within the YAML file.

  • dev/yaml.txt
  • Last modified: 2024/06/19 13:31
  • by 127.0.0.1