add: add jsonl to json py script

This commit is contained in:
wql 2024-08-12 15:23:43 +08:00
parent ce742cdb8f
commit 9698ef9781
1 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,20 @@
import json
def jsonl_to_json(jsonl_file, json_file):
with open(jsonl_file, 'r', encoding='utf-8') as f:
jsonl_data = f.readlines()
# print(jsonl_data)
# print(jsonl_data[0])
# print(jsonl_data[0][1:-2])
# print(jsonl_data[14])
with open(json_file, 'w', encoding='utf-8') as f:
for line in jsonl_data:
line = line[1:-2]
f.write(' ' + line + ',' + '\n')
f.close()
jsonl_file = 'jsonl_data/alpaca_zh.jsonl'
json_file = 'data/alpaca_zh.json'
jsonl_to_json(jsonl_file, json_file)