YAML
What is YAML?
Clark Evans proposed YAML in 2001. Ingy döt Net and Oren Ben-Kiki are also among the first authors. The name means YAML Ain't Markup Language. It was first counted as Yet Another Markup Language, then changed to say it is not a markup language. A key and a value are split by a colon. A list starts with a dash. The lines of the same block indent with the same number of spaces. A tab is not used in place of a space. Docker Compose, GitHub Actions, and many server settings read this file. The file itself runs nothing. The program that reads it does the work.
What is YAML used for?
YAML is for a setting a person can read. A list, a name, and a value stay in one file.
- Writing a server's port and name
- Keeping the list of a job with several steps
- Writing the setting of Docker services
- Changing the same key in several environments
What can you do with YAML?
With YAML you write a key, a list, and a nested block. It does not run a calculation and it does not draw a page. The program must read the file by its own rule. A wrong indent pulls another block inside, and the program sees another setting. Do not put a password in this file into the repo.
Is YAML hard to learn?
Writing two lines is easy. The difficulty is the number of spaces. When one line indents too little or too much, the block breaks. When a tab and a space mix, the program that reads it stops. The same word is sometimes counted as text, sometimes as true or false, and sometimes as a number. Leaving that by accident changes the setting. In JSON a brace shows the place that did not close. In YAML the mistake is quieter.
Advantages and limits
Advantage: the file reads short, a comment can be written, and a list looks quieter than JSON. Limit: an indent mistake gives another meaning. YAML is not JSON and it is not a program.
Basic ideas
A key is a name. A value is what is written to that name. The indent says which block it is inside.
- A colon splits a key from a value
- A dash is a list item
- A space counts, a tab does not
- The file itself does not run a program
A short example
This writes a server's name and port. It does not start the program.
name: nibras port: 8080
Common questions
- Are YAML and JSON the same? No. Both can keep a setting. JSON uses braces. YAML uses indent, and a comment can be written.
- Is YAML a programming language? No. The program that reads the file does the work. YAML itself runs nothing.
- Can indent be a tab? No. Indent is written with spaces. A tab can stop the reader.