I have a function:
def save(path,data): file = open(path,'w',encoding='utf-8') file.write(json.dumps(data)) file.close()
It saves the file, but without tabbing. Everything goes in one line.
save('1.json',{"1":"222"})
How do I make it save in tab format?
{ "1":"222" }
Use indent argument with json.dumps as below:
indent
json.dumps
import json def save(path, data): file = open(path,'w',encoding='utf-8') file.write(json.dumps(data, indent=4)) file.close() save('1.json',{"1":"222"})
2.1m questions
2.1m answers
60 comments
57.0k users