|
、>
の違いを分かりやすく解説( |
は行末が改行 \n
、>
は行末が半角スペース
になる)&
とエイリアス *
YAML
はJSON
のスーパーセットJSON
でできることはYAML
でできるシステム間での可搬性を維持するために、タブ文字は設計上許可されていないため、代わりに空白文字 (リテラルスペース文字) を使用します。
YAML 初心者によくある質問は「3 つのダッシュは何を意味するのか」ですが、3 つのダッシュ (---) はドキュメントの開始を示すために使用し、各ドキュメントの終了を示すには 3 つのドット (...) を使用します。
#Comment: This is a supermarket list using YAML
#Note that - character represents the list
---
food:
- vegetables: tomatoes #first list item
- fruits: #second list item
citrics: oranges
tropical: bananas
nuts: peanuts
sweets: raisins
employees:
- yamada
- tanaka
- sato
{
"employees": [
"yamada",
"tanaka",
"sato"
]
}
employees:
- employee1: '0001' # ''で囲まないと0001 は 1と解釈
name: yamada
- employee2: '0002'
name: tanaka
- employee3: '0003'
name: sato
{
"employees": [
{
"employee1": "0001",
"name": "yamada"
},
{
"employee2": "0002",
"name": "tanaka"
},
{
"employee3": "0003",
"name": "sato"
}
]
}
>
または|
を使用引用元:https://qiita.com/jerrywdlee/items/d5d31c10617ec7342d56
foo: |
bar
baz
{
"foo": "bar\nbaz"
}
foo: >
bar
baz
{
"foo": "bar baz"
}
To DRY up your config.yml, use anchors and aliases. Anchors are identified by an & character, and aliases by an * character.
song:
- &name Al
- You
- can
- call
- me
- *name
song:
- Al
- You
- can
- call
- me
- Al
引用:https://circleci.com/docs/2.0/writing-yaml/
default: &default
school: hogwarts
harry:
<<: *default
house: gryffindor
{
"default": {
"school": "hogwarts"
},
"harry": {
"house": "gryffindor",
"school": "hogwarts"
}
}
name: &harry_name
first_name: Harry
last_name: Potter
address: &harry_address
street: 4, Privet Drive
district: Little Whinging
county: Surrey
country: England
harry_data:
<<: [*harry_name, *harry_address]
※ <<:
配列はマージする。
{
"harry_data": {
"county": "Surrey",
"first_name": "Harry",
"last_name": "Potter",
"street": "4, Privet Drive",
"district": "Little Whinging",
"country": "England"
},
"name": {
"first_name": "Harry",
"last_name": "Potter"
},
"address": {
"county": "Surrey",
"country": "England",
"street": "4, Privet Drive",
"district": "Little Whinging"
}
}
例1
x: "x"
y: "y"
z:
- zX: 'zX'
zY: 'zY'
- zX: 'zX'
zY: 'zY'
{
"x": "x",
"y": "y",
"z": [
{
"zX": "zX",
"zY": "zY"
},
{
"zX": "zX",
"zY": "zY"
}
]
}
例2
vertexes:
num: 15
digit: 3
nodes:
- name: "a"
position:
x: 10
y: 20
z: 30
color: "red"
- name: "b"
position:
x: 15
y: 8
z: 30
color: "blue"
{
"vertexes": {
"num": 15,
"digit": 3,
"nodes": [
{
"name": "a",
"position": {
"x": 10,
"y": 20,
"z": 30
},
"color": "red"
},
{
"name": "b",
"position": {
"x": 15,
"y": 8,
"z": 30
},
"color": "blue"
}
]
}
}