with open(file_json, 'ab+') as f: f.seek(-1,2) char_tail = f.read(1).decode() if char_tail == ']': f.seek(-1,2) elif char_tail == '\n': f.seek(-2,2) char_tail = f.read(1) if char_tail.decode() == ']': f.seek(-2,2) else: print('*** Unknown format.') print('seek(-2,2) read -> {}'.format(char_tail)) return else: print('*** Unknown format.') print('seek(-1,2) read -> {}'.format(char_tail)) return f.truncate() f.write(', '.encode()) f.write(json.dumps(data, ensure_ascii=False).encode()[1:-1]) f.write(']'.encode())