Skip to content

Latest commit

 

History

History
112 lines (86 loc) · 2.56 KB

README.md

File metadata and controls

112 lines (86 loc) · 2.56 KB

YAML (YAML Ain't Markup Language)

YAML is like a simple language computers can understand to store and share information. It's commonly used for things like telling programs how to behave, saving settings, or passing data between different systems. The YAML acronym was shorthand for Yet Another Markup Language. But the maintainers renamed it to YAML Ain't Markup Language to place more emphasis on its data-oriented features.

Imagine YAML as a way for computers to read and write information in a way that's easy for humans to understand. It uses a straightforward structure with indentation to organize data, and you can use it for various purposes, such as setting up programs, saving lists of items, or describing configurations.

For instance, if you wanted to tell a computer about different users and their roles, you might use YAML like this:

Yaml

users:
  - username: alice
    role: admin
  - username: bob
    role: user

output: yaml into json

{
  "users": [
    {
      "username": "alice",
      "role": "admin"
    },
    {
      "username": "bob",
      "role": "user"
    }
  ]
}
Use Cases:
  • Configuration files for applications
  • Data serialization
  • Language-independent data exchange
  • Configuration management systems (e.g., Ansible, Kubernetes)
  • Writing data structures in a human-readable format
Start and End of File:
  • YAML files start with three dashes (---) to indicate the beginning.
  • The end of the file is denoted by three dots (...)
Data Types
  • Scalars: Strings, Numbers, Booleans, Null
  • Collections: Lists (Arrays), Maps (Objects), Sets
Errors
  • YAML is sensitive to indentation, and errors often arise due to - inconsistent or incorrect indentation.
  • Mismatched quotes or indentation can lead to parsing errors.
  • Incorrect use of colons and dashes can cause problems.

Examples

Scalar Types:

string: "Hello, YAML!"
number: 42
boolean: true
null_value: null

Collections:

list_example:
  - item1
  - item2
  - item3

map_example:
  key1: value1
  key2: value2

Nested Structures:

nested_map:
  key1: value1
  key2:
    - item1
    - item2

Complex Example:

application:
  name: MyApp
  version: 1.0
  settings:
    debug: true
    database:
      host: localhost
      port: 5432
  users:
    - username: alice
      role: admin
    - username: bob
      role: user

Remember that YAML is whitespace-sensitive, and indentation should be consistent to avoid parsing errors. Always refer to the YAML specification for more details and advanced features.