(jsonl_file, json_file)
| 1 | import json |
| 2 | |
| 3 | def jsonl_to_json(jsonl_file, json_file): |
| 4 | with open(jsonl_file, 'r') as infile: |
| 5 | with open(json_file, 'w') as outfile: |
| 6 | json_lines = infile.readlines() |
| 7 | json_list = [json.loads(line) for line in json_lines] |
| 8 | json.dump(json_list, outfile, indent=4) |
| 9 | |
| 10 | # 用法示例 |
| 11 | jsonl_to_json('ToG_cwq.jsonl', 'ToG_cwq.json') |