From the course: Effective Serialization with Python

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Streaming JSON

Streaming JSON - Python Tutorial

From the course: Effective Serialization with Python

Start my 1-month free trial

Streaming JSON

- In some cases you'd like to stream data. It can happen, for example, when you don't know how many objects there are or when there are too many objects to encode in one pass. Sadly, the Json format allow encoding of only one object at a time. One option is to emulate the big list amidst an opening square bracket at the beginning, then the objects separated by commas and finally, closing square bracket, which makes it adjacent list. This can work on the serialization side but there is no way with the built in Json decoder to deserialize partial data. The common solution is to write one Json object per line. This way the client will read the line, deserialize the object and work with it. Let's have a look. Here we have streaming.py, we input Json and to emulate the network we're going to use BytesIO. We have our groups. A group of Bees is called the swarm, a group of foxes is called the charm, and a group of whales is…

Contents