List, set or Dictionary?

I do not think json.dump() will edit an existing JSON for you when you give it a file opened in mode "a". :slight_smile: 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:

  1. Read the original JSON file.
  2. Edit the structure in memory.
  3. Use json.dump() to overwrite the original JSON file (opened in mode "w").
1 Like