Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json_fix
- def fix_instructions(file_path):
- with open(file_path, 'r', encoding='utf-8-sig') as f:
- lines = f.readlines()
- for i, line in enumerate(lines):
- if line.strip().startswith('"instruction":'):
- first_quote = line.find('"', line.find(':'))
- last_quote = line.rfind('"')
- # Remove all problematic characters between the quotes
- new_line = line[:first_quote+1] + ''.join(c for c in line[first_quote+1:last_quote] if c.isalnum() or c.isspace()) + line[last_quote:]
- lines[i] = new_line
- with open(file_path, 'w', encoding='utf-8-sig') as f:
- f.writelines(lines)
- file_path = r"C:\SD\updated_updated_combined.json"
- fix_instructions(file_path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement