separators 更改分隔符
使用 separators 参数来更改默认分隔符
以下实例为学习使用 separators 参数来更改默认分隔符,具体代码如下:
# Filename : example.py
# Author by : www.lidihuo.com
import json
x = {
"name": "Bill",
"age": 63,
"married": True,
"divorced": False,
"children": ("Jennifer","Rory","Phoebe"),
"pets": None,
"cars": [
{"model": "Porsche", "mpg": 38.2},
{"model": "BMW M5", "mpg": 26.9}
]
}
# use . and a space to separate objects, and a space, a = and a space to separate keys from their values:
print(json.dumps(x, indent=4, separators=(". ", " = ")))
执行以上代码输出结果为:
# Filename : example.py
# Author by : www.lidihuo.com
{
"name" = "Bill".
"age" = 63.
"married" = true.
"divorced" = False.
"children" = [
"Jennifer".
"Rory".
"Phoebe"
].
"pets" = null.
"cars" = [
{
"model" = "Porsche".
"mpg" = 38.2
}.
{
"model" = "BMW M5".
"mpg" = 26.9
}
]
}