Skip to content

Instantly share code, notes, and snippets.

@mazieres
Created January 26, 2017 20:33
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 mazieres/a704da41f599faceaedc69c7966bac95 to your computer and use it in GitHub Desktop.
Save mazieres/a704da41f599faceaedc69c7966bac95 to your computer and use it in GitHub Desktop.
import json
from json.decoder import WHITESPACE
def iterload(string, cls=json.JSONDecoder, **kwargs):
decoder = cls(**kwargs)
idx = WHITESPACE.match(string, 0).end()
while idx < len(string):
try:
obj, end = decoder.raw_decode(string, idx)
idx = WHITESPACE.match(string, end).end()
yield obj
except Exception, e:
idx = WHITESPACE.match(string, end).end()
print e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment