在Python中,可以使用json.dumps()函数自定义JSON对象的输出格式
import jsondata = { "name": "John", "age": 30, "city": "New York"}# 自定义缩进和分隔符json_string = json.dumps(data, indent=4, separators=(',', ': '))print(json_string)输出结果:
{ "name": "John", "age": 30, "city": "New York"}在这个例子中,我们使用indent参数设置了缩进为4个空格,并使用separators参数设置了键值对之间的分隔符为冒号加一个空格。你可以根据需要调整这些参数来获得所需的输出格式。


