Skip to content

Instantly share code, notes, and snippets.

@iamkhush
Created September 6, 2013 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamkhush/6459430 to your computer and use it in GitHub Desktop.
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
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