cases_dict_generate.py 717 B

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