File size: 831 Bytes
625a17f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
28
import json

# filepath: /home/yuqian_fu/merge_results.py
# 定义两个 JSON 文件的路径
json_file_1 = "/path/to/first_result.json"
json_file_2 = "/path/to/second_result.json"
output_file = "/path/to/merged_result.json"

# 加载两个 JSON 文件
with open(json_file_1, "r") as f1, open(json_file_2, "r") as f2:
    result_1 = json.load(f1)
    result_2 = json.load(f2)


# 检查是否有重复的 take_id
overlap = set(result_1) & set(result_2)
if overlap:
    print(f"WARNING: 以下 take_id 在两个文件中都出现了,将以第二个文件为准覆盖:{sorted(overlap)}")


# 合并两个 result 字典
merged_result = {**result_1, **result_2}

# 将合并后的结果保存到新的 JSON 文件
with open(output_file, "w") as out:
    json.dump(merged_result, out)

print(f"Merged result saved to {output_file}")