令人崩溃的yaml(yml配置)对比properties、json、TOML

编程入门 行业动态 更新时间:2024-10-23 22:31:28

 

经过:原本,我一直以为,yml格式非常好用,至少比 properties要科学,比 json 要简洁、强大然而,下面遇到的这个案例,让我意识到,yaml并不是万能,也并不是最科学、简洁的,甚至是比较糟糕的

 

我有这样一个 spring-boot的配置文件(原本是properties格式如下):

keycloak.realm = demo

keycloak.resource = fm-cache-cloud

keycloak.credentials.secret = d4589683-0ce7-4982-bcd3

keycloak.security[0].authRoles[0] = user

keycloak.security[0].collections[0].name = sso login url

keycloak.security[0].collections[0].patterns[0] = /login/*

还是比较直观,而且 借助复制粘贴 写起来倒也简单。

然而,我在另一个新项目中,想把它转换成 yaml格式,很快,我发现不妙,不信你可以试试。

我转换的结果是这样的:

keycloak:

    realm: demo

    resource: fm-cache-cloud

    credentials: 

        secret: d4589683-0ce7-4982-bcd3

    security:

        

            authRoles:

                - user

            collections: 

                

                    name: sso login url

                    patterns: 

                        /manage/ssologin/*

转换费了我不少功夫,而且一看,这是什么玩意儿啊,乱七八糟的,不直观,反人类啊。

 

于是 我找到了一个 “像样的人类可读的格式”(easy for humans to read and write)

——那就是 TOML。

 

GitHub 目前的新项目已经转用 CoffeeScript 了。CoffeeScript 比JavaScript 要简洁优雅得多。

同样地,GitHub 也觉得 YAML 不够简洁优雅,因此捣鼓出了一个TOML。

 

TOML 的全称是 Tom's Obvious, Minimal Language,因为它的作者是 GitHub 联合创始人 Tom Preston-Werner 。

 

TOML 的目标

TOML 的目标是成为一个极简的配置文件格式。TOML 被设计成可以无歧义地被映射为哈希表,从而被多种语言解析。

 

例子

title = "TOML 例子"

 

[owner]

name = "Tom Preston-Werner"

organization = "GitHub"

bio = "GitHub Cofounder & CEO\nLikes tater tots and beer."

dob = 1979-05-27T07:32:00Z # 日期时间是一等公民。为什么不呢?

 

[database]

server = "192.168.1.1"

ports = [ 8001, 8001, 8002 ]

connection_max = 5000

enabled = true

 

[servers]

 

  # 你可以依照你的意愿缩进。使用空格或Tab。TOML不会在意。

  [servers.alpha]

  ip = "10.0.0.1"

  dc "eqdc10"

 

  [servers.beta]

  ip = "10.0.0.2"

  dc "eqdc10"

 

[clients]

data = [ ["gamma""delta"], [1, 2] ]

 

# 在数组里换行没有关系。

hosts = [

  "alpha",

  "omega"

]

详见官方文档:https://github/toml-lang/toml/blob/master/versions/cn/toml-v0.5.0.md

 

TOML的实现和各种语言支持

如果你有一个实现,请发一个合并请求,把你的实现加入到这个列表中。请在你的解析器的 README 中标记你的解析器支持的 提交SHA1 或 版本号。

  • C#/.NET - https://github/LBreedlove/Toml

  • C#/.NET - https://github/rossipedia/toml-net

  • C#/.NET - https://github/RichardVasquez/TomlDotNet

  • C (@ajwans) - https://github/ajwans/libtoml

  • C++ (@evilncrazy) - https://github/evilncrazy/ctoml

  • C++ (@skystrife) - https://github/skystrife/cpptoml

  • Clojure (@lantiga) - https://github/lantiga/clj-toml

  • Clojure (@manicolosi) - https://github/manicolosi/clojoml

  • CoffeeScript (@biilmann) - https://github/biilmann/coffee-toml

  • Common Lisp (@pnathan) - https://github/pnathan/pp-toml

  • Erlang - https://github/kalta/etoml.git

  • Erlang - https://github/kaos/tomle

  • Emacs Lisp (@gongoZ) - https://github/gongo/emacs-toml

  • Go (@thompelletier) - https://github/pelletier/go-toml

  • Go (@laurent22) - https://github/laurent22/toml-go

  • Go w/ Reflection (@BurntSushi) - https://github/BurntSushi/toml

  • Haskell (@seliopou) - https://github/seliopou/toml

  • Haxe (@raincole) - https://github/raincole/haxetoml

  • Java (@agrison) - https://github/agrison/jtoml

  • Java (@johnlcox) - https://github/johnlcox/toml4j

  • Java (@mwanji) - https://github/mwanji/toml4j

  • Java - https://github/asafh/jtoml

  • Java w/ ANTLR (@MatthiasSchuetz) - https://github/mschuetz/toml

  • Julia (@pygy) - https://github/pygy/TOML.jl

  • Literate CoffeeScript (@JonathanAbrams) - https://github/JonAbrams/tomljs

  • node.js - https://github/aaronblohowiak/toml

  • node.js/browser - https://github/ricardobeat/toml.js (npm install tomljs)

  • node.js - https://github/BinaryMuse/toml-node

  • node.js (@redhotvengeance) - https://github/redhotvengeance/topl (topl npm package)

  • node.js/browser (@alexanderbeletsky) - https://github/alexanderbeletsky/toml-js (npm browser amd)

  • Objective C (@mneorr) - https://github/mneorr/toml-objc.git

  • Objective-C (@SteveStreza) - https://github/amazingsyco/TOML

  • Ocaml (@mackwic) https://github/mackwic/to.ml

  • Perl (@alexkalderimis) - https://github/alexkalderimis/config-toml.pl

  • Perl - https://github/dlc/toml

  • PHP (@leonelquinteros) - https://github/leonelquinteros/php-toml.git

  • PHP (@jimbomoss) - https://github/jamesmoss/toml

  • PHP (@coop182) - https://github/coop182/toml-php

  • PHP (@checkdomain) - https://github/checkdomain/toml

  • PHP (@zidizei) - https://github/zidizei/toml-php

  • PHP (@yosymfony) - https://github/yosymfony/toml

  • Python (@socketubs) - https://github/socketubs/pytoml

  • Python (@f03lipe) - https://github/f03lipe/toml-python

  • Python (@uiri) - https://github/uiri/toml

  • Python - https://github/bryant/pytoml

  • Python (@elssar) ) https://github/elssar/tomlgun

  • Python (@marksteve) - https://github/marksteve/toml-ply

  • Python (@hit9) - https://github/hit9/toml.py

  • Ruby (@jm) - https://github/jm/toml (toml gem)

  • Ruby (@eMancu) - https://github/eMancu/toml-rb (toml-rb gem)

  • Ruby (@charliesome) - https://github/charliesome/toml2 (toml2 gem)

  • Ruby (@sandeepravi) - https://github/sandeepravi/tomlp (tomlp gem)

  • Scala - https://github/axelarge/tomelette

校验

@BurntSushi) - https://github/BurntSushi/toml/tree/master/tomlv

TOML 测试套件 (语言无关)

  • toml-test (@BurntSushi) - https://github/BurntSushi/toml-test

编辑器支持

  • Emacs (@dryman) - https://github/dryman/toml-mode.el

  • Sublime Text 2 & 3 (@lmno) - https://github/lmno/TOML

  • TextMate (@infininight) - https://github/textmate/toml.tmbundle

  • Vim (@cespare) - https://github/cespare/vim-toml

编码器

  • PHP (@ayushchd) - https://github/ayushchd/php-toml-encoder

 

 

 

更多推荐

令人崩溃的yaml(yml配置)对比properties、json、TOML

本文发布于:2023-06-13 22:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1412477.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:yml   yaml   properties   TOML   json

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!