import json

def merge_label(file_a_path, file_b_path, output_path):
    # 读取文件A
    with open(file_a_path, 'r', encoding='utf-8') as f:
        data_a = json.load(f)
    
    # 读取文件B
    with open(file_b_path, 'r', encoding='utf-8') as f:
        data_b = json.load(f)
    
    # 构建文件A的 id 到 label 的映射
    label_map = { item["id"]: item["label"] for item in data_a }

    # 对文件B中的数据进行合并
    for item in data_b:
        id_ = item.get("id")
        if id_ in label_map:
            item["label"] = label_map[id_]
        else:
            print(f"Warning: id {id_} not found in file A")

    # 输出合并后的新文件
    with open(output_path, 'w', encoding='utf-8') as f:
        json.dump(data_b, f, indent=4, ensure_ascii=False)

    print(f"Merge completed. New file saved to: {output_path}")

# 示例用法
if __name__ == "__main__":
    # 修改成你的实际文件路径
    file_a_path = 
    file_b_path = 
    output_path = 

    merge_label(file_a_path, file_b_path, output_path)
