问题描述
如何在 YAML 中创建嵌套列表?我想得到:
How can I create nested lists in YAML? I want to get:
{"Hello": ["as", ["http://", ["cat"]]]}
这是我的 YAML 不起作用(使用 pyYaml):
Here's my YAML that doesn't work (with pyYaml):
Hello:
- "as"
- "http://"
- cat
我做错了什么?
具体来说,我正在尝试从 YAML 生成以下 JSON:
Specifically, I'm trying to generate the following JSON from YAML:
"URL" : {
"Description" : "URL of the website",
"Value" : { "Fn::Join" : [ "", [ "http://", { "Fn::GetAtt" : [ "ElasticLoadBalancer", "DNSName" ]}]]}
}
这是我使用过的最接近的 YAML,但它不能完全满足我的需求.
Here's the closest YAML I've got working, but it doesn't give quite what I need.
YAML 是:
Outputs:
URL:
Description: URL of the website
Value:
"Fn::Join":
- ""
- "http://"
- "Fn::GetAtt":
- ElasticLoadBalancer
- DNSName
结果:
"URL": {
"Description": "URL of the website",
"Value": {
"Fn::Join": [
"",
"http://",
{
"Fn::GetAtt": [
"ElasticLoadBalancer",
"DNSName"
]
}
]
}
}
这几乎是正确的,但是在 ""
之后应该有一个嵌套列表,而不仅仅是另一个列表项.我该如何解决这个问题?
This is almost correct, but after ""
there should be a nested list, not just another list item. How can I fix this?
这将被送入 API,因此输出必须完全匹配.
This is going to be fed into an API, so the output must match completely.
推荐答案
答案是:
URL:
Description: URL of the website
Value:
"Fn::Join":
- ""
- - "http://"
- "Fn::GetAtt":
- ElasticLoadBalancer
- DNSName
(见 http://pyyaml.org/wiki/PyYAMLDocumentation#YAMLsyntax - "block序列可以嵌套")
(see http://pyyaml.org/wiki/PyYAMLDocumentation#YAMLsyntax - "block sequences can be nested")
这篇关于yaml 中的嵌套列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!