File size: 1,030 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 31 32 |
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)}") |