with open(filename, 'ab+') as f: f.seek(-1,2) f.truncate() f.write(', '.encode()) f.write(json.dumps(data, ensure_ascii=False).encode()[1:-1]) f.write(']'.encode())