Код: Выделить всё
It was not possible correct the JSON: Extra data: line 1 column 3 (char 2)
JSON decoding error on line: Extra data: line 1 column 7 (char 6)
Вот фрагмент кода скрипта (не буду приводить его полностью, чтобы не делать этот пост слишком длинным):
Код: Выделить всё
item = json.loads(line)
return item
except json.JSONDecodeError as e:
print(f"Unable to fix JSON: {e}")
return None
# Open input file
with open(input_file, 'r', encoding='utf-8') as in_file:
for line in in_file:
# Tenta corrigir a linha
fixed_line = fix_json_line(line.strip())
if fixed_line:
fixed_messages.append(fixed_line)
else:
unfixed_lines.append(line)
# Saves corrected messages to a new JSON file
with open(output_file, 'w', encoding='utf-8') as out_file:
json.dump(fixed_messages, out_file, ensure_ascii=False, indent=2)
# Saves lines that could not be corrected in a separate file
if unfixed_lines:
with open('unfixed_lines.txt', 'w', encoding='utf-8') as unfixed_file:
unfixed_file.writelines(unfixed_lines)
print(f"Lines that could not be corrected were saved in 'unfixed_lines.txt'")
else:
print("All lines were successfully corrected.")
print(f"Lines corrected and saved in {output_file}")
Код: Выделить всё
{
"id": 610775,
"type": "message",
"date": "2024-06-27T13:55:13",
"date_unixtime": "1719507313",
"from": "Swelve",
"from_id": "user5957514107",
"reply_to_message_id": 610761,
"text": "antes de pisar numa universidade ele deveria revisar esse português dele",
"text_entities": [
{
"type": "plain",
"text": "antes de pisar numa universidade ele deveria revisar esse português dele"
}
]
},
{
"id": 610776,
"type": "message",
"date": "2024-06-27T13:56:31",
"date_unixtime": "1719507391",
"from": "Old dirty bastard λ",
"from_id": "user1758042831",
"text": "No mínimo",
"text_entities": [
{
"type": "plain",
"text": "No mínimo"
}
]
}
]
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... be-causing