基本上尝试使用这个json可以完成的yaml:
{
models:
[
{
model: "a"
type: "x"
#bunch of properties...
},
{
model: "b"
type: "y"
#bunch of properties...
}
]
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是我所拥有的,它不起作用,因为我正在重复我的model密钥,但通过保持关键词,这可能是一个正确的方法model吗?
models:
model:
type: "x"
#bunch of properties...
model:
type: "y"
#bunch of properties...
Run Code Online (Sandbox Code Playgroud)
Cha*_*ffy 86
使用短划线开始新的列表元素:
models:
- model: "a"
type: "x"
#bunch of properties...
- model: "b"
type: "y"
#bunch of properties...
Run Code Online (Sandbox Code Playgroud)
Ant*_*hon 36
你可能一直在看YAML太久了,因为你在帖子中称之为JSON的不是,它更像是YAML和JSON的一半.让我们跳过JSON不允许以a开头的注释的事实#,你应该引用作为键的字符串,你应该放在,映射中的元素之间:
{
"models":
[
{
"model": "a",
"type": "x"
},
{
"model": "b",
"type": "y"
}
]
}
Run Code Online (Sandbox Code Playgroud)
这是正确的JSON以及它是YAML,因为YAML是JSON的超集.您可以在此YAML解析器上在线检查.
您可以使用ruamel.yaml.cmd(基于我的增强版PyYAML :)将它转换为您似乎更喜欢YAML的块样式 pip install ruamel.yaml.cmd.您可以使用其命令行实用程序将JSON转换为块YAML(在版本0.9.1中,您也可以强制流式):
yaml json in.json
Run Code Online (Sandbox Code Playgroud)
哪个让你:
models:
- model: a
type: x
- model: b
type: y
Run Code Online (Sandbox Code Playgroud)
有一些在线资源允许您执行上述操作,但与任何此类服务一样,请勿将其用于任何重要事项(例如信用卡号和密码列表).
| 归档时间: |
|
| 查看次数: |
31552 次 |
| 最近记录: |