import json test_data = json.load(open("reformat_test.json", 'r')) new_data = {} for d in test_data: # image1 = d["img0"] # image2 = d["img1"] # image_id = "%s_%s" % (image1, image2) image_id = d["uid"] new_data[image_id] = d["sents"] json.dump(new_data, open("reformat_test_all.json", "w"))