所以我有{'key1'形式的python字典:[value1,value2]}, 我希望以格式:
将其写入json文件{
"key1": [value1, value2],
"key2": [value, value],
....
}
我目前正在使用json.dump(dictionary,file_to_write_to),输出如下:
{"key1": [value1, value2], "key2": [value, value]}
答案 0 :(得分:0)
使用此处定义的json pretty print:
答案 1 :(得分:0)
来自simplejson文档(参见漂亮的打印)https://simplejson.readthedocs.io/en/latest/
>>> import simplejson as json
>>> print(json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4 * ' '))
{
"4": 5,
"6": 7
}