Intention/generated_data/合并数据.py

32 lines
1.1 KiB
Python
Raw Normal View History

2025-03-16 15:33:44 +08:00
import json
import os
# 目录路径
directory = "output"
# 确保目录存在
if not os.path.exists(directory):
os.makedirs(directory)
# 读取多个 JSON 文件并合并
def merge_json_files(file_list, output_file):
merged_data = []
# 遍历每个文件
for file in file_list:
with open(f"data/{file}", 'r', encoding='utf-8') as f:
data = json.load(f) # 读取 JSON 文件
merged_data.extend(data) # 合并数据
# 将合并后的数据写入新文件
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(merged_data, f, ensure_ascii=False, indent=4)
# 文件列表
files = ['互联网查询.json','天气查询.json','知识问答.json','作业考勤人数.json', '周计划作业内容.json', '周计划数量查询.json','施工人数.json','日计划作业内容.json','日计划数量查询.json','页面切换.json','通用对话.json']
2025-03-16 15:33:44 +08:00
output_file = 'output/merged_data.json'
# 执行合并
merge_json_files(files, output_file)
print("合并完成,结果保存在 'merged_data.json'")