Open WangYQ999 opened 2 months ago
import json
def process_json_lines(input_file, output_file):
fixed_data = []
with open(input_file, 'r', encoding='utf-8') as infile:
for line in infile:
try:
# 解析每一行JSON数据
json_data = json.loads(line.strip())
# 这里可以根据需要对json_data进行处理
fixed_data.append(json_data)
except json.JSONDecodeError as e:
print(f"Error decoding JSON: {e} in line: {line}")
# 将所有解析和处理后的数据写入输出文件,格式化为JSON数组
with open(output_file, 'w', encoding='utf-8') as outfile:
json.dump(fixed_data, outfile, ensure_ascii=False, indent=4)
input_file = 'gptwords.json'
output_file = 'gptwords.out.json'
process_json_lines(input_file, output_file)
JSON: gptwords.out.json SQL: words.txt
同问