So I am trying to modify some json file and I want to be consistent with its own style. I managed to handle order of keys, separators, etc, but I can't print empty list across few lines (see diff image above).
Here's the code snippet I have for this task.
info = json.load(f, object_pairs_hook=OrderedDict)
# make some changes in info
f.seek(0)
f.write(json.dumps(info, separators=(',', ': '), indent=4))
f.truncate()
I thought about a workaround using .replace("[],", "[\n\n\t],")
, but it's kinda dirty (and incorrect for nested stuff). Any better way to do this? (or I am missing something in the json module?)