开发者

Yaml hierarchical data

I'd like to represent a hierarchy in yaml, and I'm not sure how. For example, I'd like to say something like this:

name: "user1"
programming-skill: 3
    java: 2
    python: 2
cooking-skill: 4

When I throw this at a yaml parser, I get an error along the lines of "mapping values not allowed here" on the line java: 2 because I'm trying to ass开发者_如何转开发ign programming-skill to both 3 and the list {java: 2, python: 2}.

What's the cleanest way to represent this hierarchical structure in yaml? Alternatively, is there a serialization format more suited than yaml to hierarchical structures?


name: "user1"
programming-skill: 
  - 3
  - java: 2
    python: 2
cooking-skill: 4

or if you prefer:

name: "user1"
programming-skill: 
  - 3
  - 
    java: 2
    python: 2
cooking-skill: 4


name: "user1"
programming-skill:
        others:
            java: 2
            python: 2
        value: 3
cooking-skill: 4

Test it here


It looks like it's not possible to cleanly do this in yaml. You have to, as Andrey suggested, introduce new data (others/value) and work around it. I'm still not sure if there's a format that's better suited for this form of data, or if you just have to bite the bullet and introduce an extra level of hierarchy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜