ebb/iterparse.py
2021-01-14 12:26:55 -05:00

23 lines
535 B
Python

#!/usr/bin/python
# -*- coding:utf-8 -*-
# apparently json.loads doesn't parse multiple entry json??
# So we gotta fux with it
# via https://stackoverflow.com/questions/22112439/valueerror-extra-data-while-loading-json
import json
import re
nonspace = re.compile(r'\S')
def parsy(j):
decoder = json.JSONDecoder()
pos = 0
while True:
matched = nonspace.search(j, pos)
if not matched:
break
pos = matched.start()
decoded, pos = decoder.raw_decode(j, pos)
yield decoded