File size: 1,035 Bytes
3d27cfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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)