json dumps with indent code example
Example 1: python write to json with indent
import json
# alphabetic dictionary
json_data = {hex(k): chr(k) for k in range(ord('a'), ord('z') + 1)}
# to file
with open("my_json.json", "w") as file:
json.dump(json_data, file, indent=4, sort_keys=True)
Example 2: python json dump
import json
with open("data_file.json", "w") as write_file:
json.dump(data, write_file)