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}.")