Last active
January 3, 2026 17:18
-
-
Save deniska/613cb28b4de29e0158d00d55b15149e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| def bad_json_append_please_donʼt(filename, data): | |
| with open(filename, 'rb+') as f: | |
| f.seek(-1, 2) | |
| if f.tell() > 1: | |
| f.write(b',') | |
| f.write(json.dumps(data).encode('utf-8')) | |
| f.write(b']') | |
| with open('database.json', 'w') as f: | |
| f.write('[]') | |
| bad_json_append_please_donʼt('database.json', {'a': 'b'}) | |
| bad_json_append_please_donʼt('database.json', {'c': 'd'}) | |
| with open('database.json') as f: | |
| print(f.read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment