"What is YAML?" in 60 seconds
A "Thing" = Key-Value Pairs
name: WRM v11
price: 880
weight: 63
- attribute name: attribute value
- For example, this YAML means this "thing" has a name, price, and weight
- Its name is "WRM v11", price is 880, etc
Nested: A Value can be a "Thing"
Year: 2025
Topic: Best cubes
Best 3x3:
name: WRM v11
price: 880
weight: 63
Best 4x4:
name: Aosu v7
price: 1030
weight: 181
- When the value is another "thing", it is indented
- For example, this YAML itself is a thing, which describes best cubes in 2025
- And this thing contains two attributes that are also things: Best 3x3 and Best 4x4
- The name, price, and weight of Best 3x3 are indented. They are attributes of Best 3x3
A List of Things = Dash + Indent
- GAN
- MoYu
- YJ MGC
- DaYan
- A list contains several items, each of which begins with a dash
- For example, this YAML describes a list of cube brands
An item can be a complex thing as well, like this:
- name: GAN
famous: 3x3 and skewb
- name: MoYu
famous: 3x3 and big cubes
- name: YJ MGC
famous: SQ1 and budget big cubes
- name: DaYan
famous: megaminx
- This still describes a list of brands, but each item is made of the brand name and what the brand is famous
for
- Notice the "indents" before
name and famous, they are attributes of an item
- Dashes only begin the item, not the attributes. 4 dashes, 4 items
A Value can be a "List"
Best 3x3:
- name: WRM v11
price: 880
- name: GAN16
price: 1930
Best 4x4:
name: Aosu v7
price: 1030
- This YAML describes two attributes: Best 3x3 and Best 4x4
- There's only one best 4x4, but there are two best 3x3 items. Each 3x3 item is a thing
(key-value attributes)
- Notice there are 2-space indents (1 level) before the dashes already (because the list itself is the value of
"Best 3x3")
- Notice "name" and "price" are indented by 2 levels (4 spaces), because they are the attributes of the item
with
1-level indentation
「什麼是 YAML?」60 秒快速入門
一個「東西」= 屬性 + 值
name: WRM v11
price: 880
weight: 63
- 屬性名稱: 屬性值 (不是全形冒號唷)
- 例如,這段 YAML 代表這個「東西」有名稱、價錢和重量
- 它的名稱是「WRM v11」,價錢是 880,依此類推
巢狀結構:值本身也可以是一個「東西」
Year: 2025
Topic: Best cubes
Best 3x3:
name: WRM v11
price: 880
weight: 63
Best 4x4:
name: Aosu v7
price: 1030
weight: 181
- 當值是另一個「東西」時,它會縮排
- 例如,這段 YAML 本身是一個東西,在描述 2025 年最佳方塊
- 而這個東西其中兩個屬性 Best 3x3 和 Best 4x4,其值本身也是東西
- Best 3x3 的 name、price 和 weight 都有縮排,是屬於 Best 3x3 的屬性
一串東西(清單) = 減號 + 縮排
- GAN
- MoYu
- YJ MGC
- DaYan
- 清單包含多個項目,每個項目都以減號開頭
- 例如,這段 YAML 在描述一個魔方品牌清單
項目也可以是複雜的東西,像這樣:
- name: GAN
famous: 3x3 and skewb
- name: MoYu
famous: 3x3 and big cubes
- name: YJ MGC
famous: SQ1 and budget big cubes
- name: DaYan
famous: megaminx
- 這仍然在描述一堆品牌,但每個項目都由品牌名稱和其強項組成
- 注意
name 和 famous 前面的「縮排」,name 和 famous 都是項目的屬性
- 減號是代表項目的開始,而不是每個屬性的開始。4 個減號,4 個項目
值可以是「清單」
Best 3x3:
- name: WRM v11
price: 880
- name: GAN16
price: 1930
Best 4x4:
name: Aosu v7
price: 1030
- 這段 YAML 描述兩個屬性:Best 3x3 和 Best 4x4
- 只有一個最佳 4x4,但有兩個最佳 3x3。每個 3x3 項目都是一個東西(屬性鍵-值)
- 注意減號前面已經有 2 空格的縮排(1 層),因為此清單本身是「Best 3x3」的值
- 注意「name」和「price」縮排了 2 層(4 空格),因為它們是「具有 1 層縮排的項目」的屬性