YAML格式的语法
基本格式
- 用空格缩进, 不能用tab
- 用#标记注释
- 列表: 用短划(-)标记元素
- 映射: 用冒号(:)分隔key, value. 如果写在一行, 需要用逗号分隔并前后加花括号
- 字符串: 不加引号, 加单引号或者加双引号都可以, 加双引号时可以使用\开头的转义字符
- 多行字符串可以用 | 或 > 符号, 紧接着换行符
- 重复的节点, 可以用 & 标识, 并用 * 来引用
基本元素
列表
# 普通
- Casablanca
- North by Northwest
- The Man Who Wasn't There # 单行
[milk, pumpkin pie, eggs, juice]
men: [John Smith, Bill Jones]
women:
- Mary Smith
- Susan Williams
映射
# Indented Block
name: John Smith
age: 33
# Inline Block
{name: John Smith, age: 33}
- {name: John Smith, age: 33}
- name: Mary Smith
age: 27
多行字符串
data: |
There once was a short man from Ealing
Who got on a bus to Darjeeling
It said on the door
"Please don't spit on the floor"
So he carefully spat on the ceiling data: >
Wrapped text
will be folded
into a single
paragraph Blank lines denote
paragraph breaks
指定类型
a: 123 # an integer
b: "123" # a string, disambiguated by quotes
c: 123.0 # a float
d: !!float 123 # also a float via explicit data type prefixed by (!!)
e: !!str 123 # a string, disambiguated by explicit type
f: !!str Yes # a string via explicit type
g: Yes # a boolean True (yaml1.1), string "Yes" (yaml1.2)
h: Yes we have No bananas # a string, "Yes" and "No" disambiguated by context. picture: !!binary |
R0lGODdhDQAIAIAAAAAAANn
Z2SwAAAAADQAIAAACF4SDGQ
ar3xxbJ9p0qa7R0YxwzaFME
1IAADs=
myObject: !myClass { name: Joe, age: 15 }
另一篇简明的介绍, from https://learnxinyminutes.com/docs/yaml/
--- # document start # Comments in YAML look like this. ################
# SCALAR TYPES #
################ # Our root object (which continues for the entire document) will be a map,
# which is equivalent to a dictionary, hash or object in other languages.
key: value
another_key: Another value goes here.
a_number_value: 100
scientific_notation: 1e+12
# The number 1 will be interpreted as a number, not a boolean. if you want
# it to be interpreted as a boolean, use true
boolean: true
null_value: null
key with spaces: value
# Notice that strings don't need to be quoted. However, they can be.
however: 'A string, enclosed in quotes.'
'Keys can be quoted too.': "Useful if you want to put a ':' in your key."
single quotes: 'have ''one'' escape pattern'
double quotes: "have many: \", \0, \t, \u263A, \x0d\x0a == \r\n, and more." # Multiple-line strings can be written either as a 'literal block' (using |),
# or a 'folded block' (using '>').
literal_block: |
This entire block of text will be the value of the 'literal_block' key,
with line breaks being preserved. The literal continues until de-dented, and the leading indentation is
stripped. Any lines that are 'more-indented' keep the rest of their indentation -
these lines will be indented by 4 spaces.
folded_style: >
This entire block of text will be the value of 'folded_style', but this
time, all newlines will be replaced with a single space. Blank lines, like above, are converted to a newline character. 'More-indented' lines keep their newlines, too -
this text will appear over two lines. ####################
# COLLECTION TYPES #
#################### # Nesting uses indentation. 2 space indent is preferred (but not required).
a_nested_map:
key: value
another_key: Another Value
another_nested_map:
hello: hello # Maps don't have to have string keys.
0.25: a float key # Keys can also be complex, like multi-line objects
# We use ? followed by a space to indicate the start of a complex key.
? |
This is a key
that has multiple lines
: and this is its value # YAML also allows mapping between sequences with the complex key syntax
# Some language parsers might complain
# An example
? - Manchester United
- Real Madrid
: [2001-01-01, 2002-02-02] # Sequences (equivalent to lists or arrays) look like this
# (note that the '-' counts as indentation):
a_sequence:
- Item 1
- Item 2
- 0.5 # sequences can contain disparate types.
- Item 4
- key: value
another_key: another_value
-
- This is a sequence
- inside another sequence
- - - Nested sequence indicators
- can be collapsed # Since YAML is a superset of JSON, you can also write JSON-style maps and
# sequences:
json_map: {"key": "value"}
json_seq: [3, 2, 1, "takeoff"]
and quotes are optional: {key: [3, 2, 1, takeoff]} #######################
# EXTRA YAML FEATURES #
####################### # YAML also has a handy feature called 'anchors', which let you easily duplicate
# content across your document. Both of these keys will have the same value:
anchored_content: &anchor_name This string will appear as the value of two keys.
other_anchor: *anchor_name # Anchors can be used to duplicate/inherit properties
base: &base
name: Everyone has same name # The regexp << is called Merge Key Language-Independent Type. It is is used to
# indicate that all the keys of one or more specified maps should be inserted
# into the current map. foo: &foo
<<: *base
age: 10 bar: &bar
<<: *base
age: 20 # foo and bar would also have name: Everyone has same name # YAML also has tags, which you can use to explicitly declare types.
explicit_string: !!str 0.5
# Some parsers implement language specific tags, like this one for Python's
# complex number type.
python_complex_number: !!python/complex 1+2j # We can also use yaml complex keys with language specific tags
? !!python/tuple [5, 7]
: Fifty Seven
# Would be {(5, 7): 'Fifty Seven'} in Python ####################
# EXTRA YAML TYPES #
#################### # Strings and numbers aren't the only scalars that YAML can understand.
# ISO-formatted date and datetime literals are also parsed.
datetime: 2001-12-15T02:59:43.1Z
datetime_with_spaces: 2001-12-14 21:59:43.10 -5
date: 2002-12-14 # The !!binary tag indicates that a string is actually a base64-encoded
# representation of a binary blob.
gif_file: !!binary |
R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5
OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+
+f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC
AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs= # YAML also has a set type, which looks like this:
set:
? item1
? item2
? item3
or: {item1, item2, item3} # Sets are just maps with null values; the above is equivalent to:
set2:
item1: null
item2: null
item3: null ... # document end
YAML格式的语法的更多相关文章
- YAML 模板文件语法
YAML 模板文件语法 默认的模板文件是 docker-compose.yml,其中定义的每个服务都必须通过 image 指令指定镜像或 build 指令(需要 Dockerfile)来自动构建. 其 ...
- k8s中yaml文常见语法
在k8s中,所有的配置都是 json格式的.但为了读写方便,通常将这些配置写成yaml 格式,其运行的时候,还是会靠yaml引擎将其转化为json,apiserver 也仅接受json的数据类型. y ...
- yaml格式配置文件
YAML 是一种可读性非常高,与程序语言数据结构非常接近.同时具备丰富的表达能力和可扩展性,并且易于使用的数据标记语言. python中处理 Yaml 格式的数据需要先下载pyyaml: pip in ...
- golang使用yaml格式解析构建配置文件
现在主流的配置文件格式有这么几种,xml.yaml.config… xml就算了,太挫了,太土, 太繁琐… config 就是mysql,apache my.cnf的那种格式,这个格式适合功能分层, ...
- JOSN学习总结<二> JSON的格式与语法
今晚又下班早!!嘿嘿,继续JOSN的总结吧!!!!有人说这么简单还有必要写吗???我觉得“眼里过十遍不如手里过一遍”!!有错误之处请指正!!共同学习下!!!!废话不说了,进入今晚的正题: <二& ...
- kubernetes yaml格式的Pod配置文件
kubernetes yaml文件解析 # yaml格式的pod定义文件完整内容: apiVersion: v1 #必选,版本号,例如v1 kind: Pod #必选,Pod metadata: #必 ...
- Unity3D可以查看YAML格式的场景文件,采用Notepad++
在Editor Settings 将Asset Serialization 的 mode设置成Force Text,否则不能查看YAML格式! Unity圣典描述:Textual Scene File ...
- Linux系统里让vim支持markdown格式的语法高亮
Markdown是深受程序员喜爱的一个文件格式. 然而Linux里默认的vim设置,并不支持markdown格式的语法高亮显示. 下面就来介绍如何设置使得markdown格式的文件在vim里也能享有语 ...
- Fiddler插件---将Mapi请求自动转为HTTPRunner测试用例(YAML格式)
背景 继之前鼓捣出了Mapi解密插件之后,在团队内已经使用了三年之久,一跃成为团队最爱欢迎的测试工具之一(加个之一,低调谦虚一点). 随着团队推行HttpRunner搞接口自动化:编写和维护Case带 ...
随机推荐
- idea 2018.1破解激活方法,有效期至2099年 idea 激活 破解
最近笔者测试了好多破解Idea的方法,最简单操作方法莫过于用license server激活,但是此类方法对最新的2017.3.2版已经无效了,亲测哦,如下图所示. 针对新版的IntelliJ ID ...
- 《JavaScript语言精粹》笔记
0.JavaScript的简单数据类型包括数字.字符创.布尔值(true/false).null和undefined值,其它值都是对象. 1.JavaScript只有一个数字类型,它在内部被表示为64 ...
- 详说 Block Formatting Contexts (块级格式化上下文)
在上文<详说清除浮动>中,Kayo 较为详细地介绍了 BFC ,也就是本文的主角 Block Formatting Contexts (块级格式化上下文),本文会基于上文关于 BFC 的部 ...
- 大数据开发实战:MapReduce内部原理实践
下面结合具体的例子详述MapReduce的工作原理和过程. 以统计一个大文件中各个单词的出现次数为例来讲述,假设本文用到输入文件有以下两个: 文件1: big data offline data on ...
- Esxi 6.0虚拟机迁移Linux遇到网络配置错误
在使用vmware迁移linux系统过程中(迁移方式是导出OVF模板和部署OVF模板),发现部署后的linux系统无法启动网卡 报错为 Bringing up interface eth0: Devi ...
- MySQL老是提示视图没有主键
写了一个视图,每次打开都提示没有主键.我又不想更新视图,根本不关心这个,但每次都提示,很烦. 网上找到解决办法,就是关闭提示: Windows 和 Linux:选择工具 > 选项,并在外观 &g ...
- Jquery中的高度
$('.someElement').height(); // returns the calculated pixel height of the element(s) $(window).heigh ...
- "Ext 4.1 Grid 'el.dom' 为空或不是对象"问题的解决
我在使用Ext 4.1 做Grid,IE下冒出这么个错误,导致表格完全显示不出来,换另外一个IE浏览器,有没有问题,呵呵,百思不得其解啊... 后来得出答案,即在grid相关代码周围套上Ext.onR ...
- [Git] Change the commit message of my last commit
Did you make a typo in your last commit message? No problem, we can use the git --amend command to c ...
- 修改mysql的默认端口号
mysql的默认端口号是3306,修改端口号的话,找到mysql的安装目录,找到my.ini文件 修改这两处的3306值,重启mysql即可