23 lines
773 B
Python
23 lines
773 B
Python
import json
|
|
|
|
def renumber_json_indices(input_file, output_file):
|
|
|
|
with open(input_file, 'r', encoding='utf-8') as f:
|
|
data = json.load(f)
|
|
idx = 1
|
|
|
|
for item in data:
|
|
item['idx'] = idx
|
|
idx = idx + 1
|
|
|
|
with open(output_file, 'w', encoding='utf-8') as f:
|
|
json.dump(data, f, ensure_ascii=False, indent=2)
|
|
|
|
print(f"成功将索引重新编号并保存到 {output_file}")
|
|
print(f"处理了 {len(data)} 条数据")
|
|
|
|
if __name__ == "__main__":
|
|
input_file = "/home/ubuntu/50T/fsy/layer2/QA/single_select.json" # 替换为你的输入文件名
|
|
output_file = "/home/ubuntu/50T/fsy/layer2/QA/single_select_renum.json" # 替换为你想要的输出文件名
|
|
|
|
renumber_json_indices(input_file, output_file) |