























配置文件用什么格式? JSON 不适合手写,YAML 缩进容易出错。TOML 看似完美,但大多数工具生成的 TOML 嵌套层级太深:
# 默认生成的
[server]
[server.database]
[server.database.connection]
host = "localhost"
port = 5432
人类更喜欢扁平的:
# 实际想要的
[server]
database.connection = {
host = "localhost",
port = 5432,
}
json-pretty-toml - 将 JSON 转换为扁平化 TOML ,遵循三个原则:
[section])section.key = value 或 section."key.name" = {...}){ ... }),使用TOML 1.1的内连风格$ echo '{"gateway":{"port":18789,"auth":{"mode":"token"}}}' | json-pretty-toml
[gateway]
port = 18789
auth.mode = "token"
支持多行内联表、自动引号转义、数组格式化等。
npm install -g json-pretty-toml
或直接用 npx:
npx json-pretty-toml < config.json > config.toml
json-pretty-toml适合需要阅读/偶尔编辑配置文件的场合
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。