MatchLab's picture
Upload folder using huggingface_hub
6f89716 verified
import json
import os
def load_json(file_path):
"""Load a JSON file and return its content."""
with open(file_path, 'r') as file:
return json.load(file)
data_files = [f'arkitscenes_caption_v{i}.json' for i in range(1, 16)]
# merge all JSON files into a single dictionary
merged_data = {}
for file_name in data_files:
file_path = os.path.join(os.getcwd(), file_name)
if os.path.exists(file_path):
data = load_json(file_path)
merged_data.update(data)
else:
print(f"File {file_name} does not exist.")
# save the merged data to a new JSON file
merged_json_path = 'arkitscenes_caption_merged.json'
with open(merged_json_path, 'w') as merged_file:
json.dump(merged_data, merged_file, indent=4)
# first five entries of the merged data
print("First five entries of merged data:")
for i, (key, value) in enumerate(merged_data.items()):
if i < 5:
print(f"{key}: {value}")
else:
break
print(f"Total number of entries in merged data: {len(merged_data)}")