I do not think json.dump()
will edit an existing JSON for you when you give it a file opened in mode "a"
. I guess it will just append a new JSON structure which will make the file to contain an invalid JSON (two JSON structures side by side).
The solution is:
- Read the original JSON file.
- Edit the structure in memory.
- Use
json.dump()
to overwrite the original JSON file (opened in mode"w"
).