**Like JSON, but more human-readable & with more [[Footgun]]s.**
YAML is a space-dependent [[Data Serialization]] method, that extends JSON. It is highly flexible and has many features JSON lacks, but in some ways is more confusing to learn and also subject to type-inferencing errors if you're not paying attention.
A [[JSON]] string is also valid YAML, but a YAML string is almost certainly not valid JSON.
YAML is a way to provide metadata to a [[Markdown]] file & is used for coding configuration files. This is called [[Frontmatter]]. It can be used for general data storage. See also: [[YAML Uses]]
There's a good [[NodeJS]] package that allows you to read/write to YAML using [[JavaScript]]. Can convert 1:1 to [[JSON]].
By trying to be more flexible, the designers of YAML included a lot of [[Footgun]]s. I have run into a simple one of these several times by accidentally making making [[Frontmatter]] contain _comments_ rather than strings by writing things like:
```yaml
name: my #1 most often screw up!
```
# Fast Facts
- Uses whitespace indentation (but not tabs)
- Can store multiple documents within a single file
- Comments start with #
- Lists can be done in two ways:
1. [item 1, item 2] (like JSON)
2. Or one per line, with the line starting with a hyphen
- Associative arrays (like Objects in JavaScript) can be done two ways:
- {key: value} (like JSON)
- with simple key, colon, space, value
- Strings typically aren't quoted, but can also be quoted or double-quoted
- If your string is meant to literally be surrounded by quotes in the way it is represented. You need to use apostrophes to encapsulate the whole thing
```yaml
quoteless: this string will passes without quotes
gotcha: "this string will parse without quotes, too"
includesquotes: '"this will parse with the quotes"'
```
```
- Can have references and tags, using an Ampersand [[Sigil]] to denote the tag location and an asterisk sigil to reference it
- The use of references allows for Graphs to be represented in YAML (not just trees, like JSON)
## Samples
```yaml
--- # The Smiths
- {name: John Smith, age: 33} #interoperability wiht JSON?
- name: Mary Smith
age: 27
- [name, age]: [Rae Smith, 4] # sequences as keys are supported
--- # People, by gender
men: [John Smith, Bill Jones]
women:
- Mary Smith
- Susan Williams
```
****
## Source
- [The Official YAML Web Site](https://yaml.org/)
- [What exactly is Frontmatter?](https://daily-dev-tips.com/posts/what-exactly-is-frontmatter/)
- [YAML - Wikipedia](https://en.wikipedia.org/wiki/YAML)
- https://ruudvanasseldonk.com/2023/01/11/the-yaml-document-from-hell
## Related
- [[Data Serialization Methods]]
- [[Data Serialization]]
- [[YAML Uses]]