bingqin111's picture
Upload folder using huggingface_hub
3d27cfe verified
Raw
History Blame Contribute Delete
1.04 kB
import json
def convert_jsonl_to_json(input_file_path, output_file_path):
"""
将 JSON Lines (JSONL) 格式的文件转换为单个 JSON 数组。
参数:
input_file_path (str): 输入的 JSONL 文件路径。
output_file_path (str): 输出的 JSON 文件路径。
"""
data = []
with open(input_file_path, 'r', encoding='utf-8') as infile:
for line in infile:
if line.strip(): # 确保行不为空
data.append(json.loads(line))
with open(output_file_path, 'w', encoding='utf-8') as outfile:
json.dump(data, outfile, ensure_ascii=False, indent=4)
print(f"转换完成!文件已保存到:{output_file_path}")
input_file = '/root/test/weitiao/data_processing_hsichen/data_process_bq/data/mistral_rm_dpo_cp2000_iter_filtered.json'
output_file = '/root/test/weitiao/data_processing_hsichen/data_process_bq/data/mistral_rm_dpo_cp2000_iter_filtered.json' # 或者您可以指定一个完整路径
convert_jsonl_to_json(input_file, output_file)