实现说明
顶层就这几处状态:settings、compact、canonical。
常见问题
它依赖第三方库吗?
没有引用任何第三方库,标准库就够了。 文件用顶层绑定保存自己的状态:settings、compact、canonical。
代码示例
import json
settings = {
"zlib_level": 6,
"cache": {"ttl": 300, "enabled": True},
"tags": ["edge", "eu"],
"owner": "platform team",
}
# indent=2 renders a readable tree that diffs line by line.
print(json.dumps(settings, indent=2))
# Compact separators squeeze out whitespace: one line, minimal bytes.
compact = json.dumps(settings, separators=(",", ":"))
print(compact)
# sort_keys fixes key order, so equal dicts serialize identically.
canonical = json.dumps(settings, sort_keys=True, separators=(",", ":"))
print(canonical)