Created
January 26, 2017 20:33
-
-
Save mazieres/a704da41f599faceaedc69c7966bac95 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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