python-yaml

示例
相同的数据使用YAML与json表示,对比如下:

  • list
    YAML
- Mark McGwire
- Sammy Sosa
- Ken Griffey

JSON

[
  "Mark McGwire", 
  "Sammy Sosa", 
  "Ken Griffey"
]
  • list type
    YAML
[Mark McGwire, Tom Curry, Steve Thompson]

JSON

[
  "Mark McGwire", 
  "Tom Curry", 
  "Steve Thompson"
]
  • dict
    YAML
hr:  65 
avg: 0.278 
rbi: 147 

JSON

{
  "hr": 65, 
  "avg": 0.27800000000000002, 
  "rbi": 147
}
  • dict involve list
    YAML
american:
  - Boston Red Sox
  - Detroit Tigers
  - New York Yankees
national:
  - New York Mets
  - Chicago Cubs
  - Atlanta Braves

JSON

{
  "american": [
    "Boston Red Sox", 
    "Detroit Tigers", 
    "New York Yankees"
  ], 
  "national": [
    "New York Mets", 
    "Chicago Cubs", 
    "Atlanta Braves"
  ]
}
  • dict involve dict
    YAML
Mark McGwire: {hr: 65, avg: 0.278}
Sammy Sosa: {
    hr: 63,
    avg: 0.288
  }

JSON

{
  "Sammy Sosa": {
    "hr": 63, 
    "avg": 0.28799999999999998
  }, 
  "Mark McGwire": {
    "hr": 65, 
    "avg": 0.27800000000000002
  }
}
  • list involve list
    YAML
- [name        , hr, avg  ]
- [Mark McGwire, 65, 0.278]
- [Sammy Sosa  , 63, 0.288]

JSON

[
  [
    "name", 
    "hr", 
    "avg"
  ], 
  [
    "Mark McGwire", 
    65, 
    0.27800000000000002
  ], 
  [
    "Sammy Sosa", 
    63, 
    0.28799999999999998
  ]
]
  • list dict

ymal

selenium_appium: appium
appium:
 - devices: "a"
   Remote: "x"
   port: ""
   appiumjs: ""
 - devices: "a"
   Remote: "x"
   port: ""
   appiumjs: ""

selenium:
 selenium_jar: ""
 sel_remote: ""
 open_url: "

json

{
    "selenium_appium": "appium",
    "appium": [
        {
            "Remote": "x",
            "port": "",
            "devices": "a",
            "appiumjs": ""
        },
        {
            "Remote": "x",
            "port": "",
            "devices": "a",
            "appiumjs": ""
        }
    ],
    "selenium": {
        "open_url": "",
        "selenium_jar": "",
        "sel_remote": ""
    }
}

Ref
Official Site
http://yaml.org/

Wiki
https://zh.wikipedia.org/zh-cn/YAML

YAML中文快速入门,有思维导图
http://www.cnblogs.com/chwkai/archive/2005/10/07/beginning_yaml.html

Online YAML parser (parse YAML to Json/XML)
https://yaml-online-parser.appspot.com/

来自:http://www.cnblogs.com/plwang1990/p/5232084.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,092评论 19 139
  • # Python 资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列...
    aimaile阅读 26,740评论 6 427
  • 前端知识体系http://www.cnblogs.com/sb19871023/p/3894452.html 前端...
    秋风喵阅读 14,310评论 7 163
  • 当世界不再前几天看到很有意思的一个话题,“关于中年少女的十五个症状”,对照了一下,蒽,中了一大半。 在成长的过程中...
    瘦出大梨涡阅读 4,106评论 0 0
  • 白天的我们快乐开心,白天的我们依旧晴朗,白天的我们一切依旧…或许是白天过得太美好了吧,我们上完课去河边捉鱼,在水里...
    失心疯疯疯子阅读 1,661评论 0 0

友情链接更多精彩内容