クイックリファレンス

YAML 構文チートシート

YAML構文のクイックリファレンス:辞書(マッピング)、リスト、複数行文字列スカラー、アンカー、エイリアス、マージキーを網羅。

· 公開日

YAML(YAML Ain't Markup Language)は、あらゆるプログラミング言語で利用できる人間にとって読みやすいデータシリアライゼーション規格です。

辞書とリスト

# Comments begin with "#"
# Dictionaries are written as "key: value"
name: Martin D'vloper
languages:
  perl: Elite
  python: Elite
  pascal: Basic

# List items begin with "- "
foods:
  - Apple
  - Orange
  - Strawberry
  - Mango

# Booleans use lowercase
employed: true

複数行文字列

# Literal Block Scalar (preserves newlines)
multiline_literal: |
  exactly as you see
  will appear these three
  lines of poetry
# Folded Block Scalar (folds newlines to spaces)
multiline_folded: >
  this is really a
  single line of text
  despite appearances

アンカーと継承

parent: &defaults
  a: 2
  b: 3

child:
  <<: *defaults
  b: 4

再利用可能なシーケンス

values: &ref
  - These values
  - will be reused below

other_values:
  <<: *ref

関連テーマ