Skip to content

Instantly share code, notes, and snippets.

@nitori
Created November 8, 2025 14:30
Show Gist options
  • Select an option

  • Save nitori/18a65743f9d0219e7f94ae4ef87c3faf to your computer and use it in GitHub Desktop.

Select an option

Save nitori/18a65743f9d0219e7f94ae4ef87c3faf to your computer and use it in GitHub Desktop.
continuous non-line delimited json stream
import subprocess, json
def parse_json_dynamic(stream):
dec = json.JSONDecoder()
buf = ''
for chunk in stream:
buf += chunk
while True:
try:
obj, idx = dec.raw_decode(buf)
except json.JSONDecodeError:
break
yield obj
buf = buf[idx:].lstrip()
import io
f = io.StringIO()
f.write("{\n")
f.write(' "hello": "world",\n')
f.write(' "nice": "test"\n')
f.write("}\n")
f.write("{\n")
f.write(' "hello": "world",\n')
f.write(' "nice": "test"\n')
f.write("}\n")
f.seek(0)
for obj in parse_json_dynamic(f):
print(obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment