so many quote '"' in captions in json files
#2
by
nanamma
- opened
such as https://huggingface.co/datasets/Enxin/MovieChat-1K_train/blob/main/jsons/S02E1-1.json#L11
i cannot load it successfully using json.load()
maybe there are so many of them that i cannot repair them by hand
it is ugly. but ok to use.
import os,io
moviechat_path="****/DATA/MovieChat-1K/"
train_json_names=os.listdir("****/DATA/MovieChat-1K/train_jsons")
import json
for json_name in train_json_names:
print(json_name)
json_path=os.path.join(moviechat_path, 'train_jsons', json_name)
with open(json_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
for i in range(8,20):
if '"caption":'in lines[i]:
lines[i]=lines[i].replace('"','\\"').replace('\\"caption\\": \\"','"caption": "')\
.replace('.\\",\n','.",\n').replace('. \\",\n','.",\n').replace('"\\"','""')\
.replace(' "caption": "\n',' "caption": "').replace('""D','"\\"D').replace('\\",\n','",\n')
break
# lines[10]=lines[10].replace('"','\\"')
# lines[10]=lines[10].replace('\\"caption\\": \\"','"caption": "')
# lines[10]=lines[10].replace('.\\",\n','.",\n')
# lines[10]=lines[10].replace('. \\",\n','.",\n')
# lines[10]=lines[10].replace('\\\\','."\\')
with open(json_path.replace('train_jsons','train_jsons_new'), 'w', encoding='utf-8') as file:
file.writelines(lines)