Created
September 6, 2013 04:05
-
-
Save iamkhush/6459430 to your computer and use it in GitHub Desktop.
This module " finds and destroys " errors in a json file by applying regex on error message, getting the column number and replacing the element on that column. Loop this thing and when no error comes save this into a new file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json, re | |
f = open('random_json_file') | |
d = f.read() | |
import time | |
starttime = time.time() | |
while True: | |
try: | |
e = json.loads(d) | |
except Exception as er: | |
column = re.match(r'.*\(\w+ (?P<column>\d+)\)$', str(er.message)) | |
column_numb = column.group(1) | |
d = '%s%s'%(d[:int(column_numb)-1],d[int(column_numb):]) | |
print 'in error', column_numb | |
else: | |
q = open('ultimate','q') | |
q.write(d) | |
q.close() | |
f.close() | |
print starttime - time.time() ,'total time' | |
exit() | |
print 'outside' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment