File size: 1,241 Bytes
6f89716
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
import json

# Input and output file paths
file1 = "/home/m50048399/transfered/ye_project/UniPointMap/PointMapVerse/existing_datasets/ScanNet/annotations/hypo3d_task/balanced/hypo3d_test.json"
file2 = "/home/m50048399/transfered/ye_project/UniPointMap/PointMapVerse/existing_datasets/ScanNet/annotations/hypo3d_task/balanced/hypo3d_val.json"
output_file = "/home/m50048399/transfered/ye_project/UniPointMap/PointMapVerse/existing_datasets/ScanNet/annotations/hypo3d_task/balanced/hypo3d_test_merged.json"

# Load both JSON files
with open(file1, "r") as f:
    data1 = json.load(f)
with open(file2, "r") as f:
    data2 = json.load(f)

# Extract "questions" lists
questions1 = data1.get("questions", [])
questions2 = data2.get("questions", [])

# Merge while deduplicating by "question_id"
merged_dict = {q["question_id"]: q for q in questions1}
for q in questions2:
    merged_dict[q["question_id"]] = q  # overwrite if same question_id

# Convert back to list
merged_questions = list(merged_dict.values())

# Save merged output
with open(output_file, "w") as f:
    json.dump({"questions": merged_questions}, f, indent=2)

print(f"Merged {len(questions1)} + {len(questions2)}{len(merged_questions)} questions saved to {output_file}.")