【问题标题】:YAML error- expected <'document start'>, but found <'block mapping start'>YAML 错误 - 预期 <'document start'>,但发现 <'block mapping start'>
【发布时间】:2020-05-20 11:09:34
【问题描述】:
我正在运行的 Bash 命令应该更新 YAML 文件。
YAML文件如下-
---
[conf]
users:
- mitchell
我得到了错误-
ERROR! Syntax Error while loading YAML.
expected '<document start>', but found '<block mapping start>'
The offending line appears to be:
users:
^ here
我该怎么办?
非常感谢!
【问题讨论】:
标签:
syntax
yaml
filesystems
config
【解决方案1】:
YAML 中的
[conf] 是一个流序列,由序列开始指示符 ([)、一项(标量 conf)和序列结束指示符 (]) 组成)。
由于一个 YAML 文档只能有一个根节点,所以文档在 ] 之后完成。 YAML 文件允许您在其中包含多个文档,以---(以及可选的...)分隔。例如,这将是有效的 YAML:
---
[conf]
---
users:
- mitchell
由于缺少分隔符,您的 YAML 解析器会抱怨它预期新文档的开头,但在根节点已关闭的当前文档中发现了更多内容。
您可能希望 [conf] 是一个特殊的语法,例如在 INI 文件中。但事实并非如此。要将以下内容放入一个部分,您只需这样做
conf:
users:
- mitchell