# Callback based streaming for the json library

**URL:** <https://discuss.python.org/t/callback-based-streaming-for-the-json-library/110370>\
**Category:** Ideas\
**Created:** [November 29, 2026, 7:19pm UTC](https://discuss.python.org/t/callback-based-streaming-for-the-json-library/110370 "2026-11-29T19:19:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nineteendo](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/nineteendo/32/19122_2.png) [@Nineteendo](https://discuss.python.org/u/Nineteendo)\
**Post date:** [November 29, 2026, 7:19pm UTC](https://discuss.python.org/t/callback-based-streaming-for-the-json-library/110370/1 "2026-11-29T19:19:26Z")

</div>

I just implemented callback based streaming for jsonyx in the C extension. [commit 472bd50](https://github.com/nineteendo/jsonyx/commit/472bd50bc3619856cd1a62a4c0b5dd2091c970f3)

```python
$ pip install git+https://github.com/nineteendo/jsonyx

```

Is this something you would like to see in the stdlib? (json.dump is implemented entirely in Python)

Processing this in a loop is a lot more complicated though:

```python
>>> import jsonyx as json
>>> from itertools import count
>>> def make_consumer(obj, **kwargs):
... def consumer(make_gen):
... class Writer:
... def write(self, chunk):
... gen.send(chunk)
... gen = make_gen()
... next(gen)
... try:
... json.dump(obj, Writer(), stream=True, **kwargs)
... finally:
... gen.close()
... return consumer
...
>>> @make_consumer([1, 2, 3])
... def _():
... for i in count():
... chunk = yield
... print(f"chunk {i}: {chunk!r}")
...
chunk 0: '['
chunk 1: '1'
chunk 2: ', '
chunk 3: '2'
chunk 4: ', '
chunk 5: '3'
chunk 6: ']'
chunk 7: '\n'

```

Sidenote: neither jsonyx or the stdlib support reading a file incrementally.
