123456789101112131415161718192021222324252627 |
- import json
- def merge_json_files(file1, file2, output_file):
- # 读取第一个JSON文件
- with open(file1, 'r', encoding='utf-8') as f1:
- data1 = json.load(f1)
- # 读取第二个JSON文件
- with open(file2, 'r', encoding='utf-8') as f2:
- data2 = json.load(f2)
- # 合并两个JSON文件的内容
- merged_data = {file1[:-5]: data1, file2[:-5]: data2}
- # 将合并后的数据写入新的JSON文件
- with open(output_file, 'w', encoding='utf-8') as output:
- json.dump(merged_data, output, ensure_ascii=False, indent=4)
- file1 = 'report-0325-1.json'
- file2 = 'report-0325-2.json'
- output = './cases_dict-0325.json'
- # 示例用法
- merge_json_files(file1, file2, output)
|