import json def jsonstream(fd): while True: try: here = fd.tell() j = json.load(fd) yield j return except json.decoder.JSONDecodeError as e: hlen = e.pos fd.seek(here) jh = fd.read(hlen) assert len(jh)==hlen j = json.loads(jh) yield j