json.dumps中indent参数是设置json缩进量的
举例:
tmp = { "aaa" : "111", "bbb" : ‘222‘}
import jsonwith open("tmp.txt", "w") as fp: fp.write(json.dumps(tmp,indent=4))打开tmp.txt查看效果
python实现将json数据以json格式写入txt文件
原文:https://www.cnblogs.com/VseYoung/p/python_json_dumps.html