YAMLは " Y
AML A
in't M
arkup L
anguage"の頭文字をとった頭字語です。これは、すべてのプログラミング言語のための人間が読めるデータ直列化標準です。
バージョン | 発売日 |
---|---|
1.0 | 2004年1月29日 |
1.1 | 2005年01月18日 |
1.2 | 2009-10-01 |
YAMLは、構造化されたデータを階層に格納することを可能にするテキストベースのフォーマットです。 YAMLは最低限のオーバーヘッドで人間と機械で読めるように設計されています。 YAML仕様はyaml.orgにあります。 参照カードもあります
コメントは#
で始まり、改行まで続き、コメントは空白で他のトークンと区切らなければなりません。空白は空白ではなく、インデントは空白でなくタブでなければなりません。 YAMLは、親キーよりも前にスペースが置かれた行がその中に含まれているとみなします。さらに、すべての行には、同じマップに属すために同じ量のスペースを接頭辞として付ける必要があります。
YAMLはコレクション型としてシーケンスとマッピングを持っていますが、どちらもフローとブロックスタイルで表現できます。
YAMLのスカラー文字列のシーケンスは以下のようになります:
[ one, two, three ] # flow style
# or block style
- one
- two
- three
マッピングは、キーと値のペアで構成されます。
index: 4 # block style
name: nali
# or
{ index: 4, name: nali } # flow style
# or nested (equivalent of { level: { one: { two: fun } } }):
level:
one:
two: fun
integer: 25
string: "25"
float: 25.0
boolean: true
null type: null
同じリストレベル:
- Cat
- Dog
- Goldfish
入れ子リスト:
-
- Cat
- Dog
- Goldfish
# This comment occupies a whole line
- some item # This comment succeeds content of a line
- http://example.com/#nocomment
- "This # does not introduce a comment."
- |
This is a block scalar.
A # inside it does not introduce a comment.
# unless it is less indented than the first line (this is one)
コメントに#
を付けるには、 #
#
は常に空白で続けなければなりません。 #
引用されたスカラーの中には決してコメントを開始しません。 #
はブロックスカラーの終わりにコメントを挿入するかもしれませんが、ブロックスカラーのベースインデント(通常は最初の空ではない行のインデントによって決まる)よりインデントされていなければなりません。
暗黙のキーの場合:
key: value
another key:
- some
- more
- values
[1, 2, 3]: last value, which has a flow style key
暗黙キーと明示キーの場合:
? key
: value
another key:
- some
- more
- values
? [1, 2, 3]
: last value, which has a flow style key
key
、 another key
および[1, 2, 3]
それらは異なるキーのスタイルを使用しているが、同一のマッピングのキーです。
ネストされたマッピング:
first level:
second level:
? third level
:
forth level: value of implicit key
? third level, second key
: value of explicit key
?
mapping as: key of
another: mapping
: scalar value of mapping key
first level, second key:
last value
- Without quotes:
You can just
split a long piece of text like this.
- With quotes:
"[But be careful:
if you \"need\" punctuation, put double quotes around it. You can ev\
en split without spaces by using backslashes."
- Or single quotes:
'This works
but isn''t as flexible'
- If you want to keep those new line characters: |
Then do
it this way with
a pipe (|) character. (This string has three \n characters)
- Or you can have just the one final new line: >
This string has
just one \n character, at the very end.
- Block indicators:
Look up >-, >+, |- and |+ for fine tuning.
YAMLは3種類のエスケープ表記をサポートしています:
エンティティエスケープ
a。スペース: " "
b。コロン: ":"
c。アンパサンド: "&"
Unicodeエスケープ
a。スペース: "\ u0020"
b。一重引用符: "\ u0027"
c。二重引用符: "\ u0022"
引用されたエスケープ
a。一重引用符で二重引用符: '私はいつも真の声明を嘘 "ですか?
b。ネストされた二重引用符: "彼女は言った、"私は "
c。ネストされた一重引用符: '彼は言葉がありませんでした:' '