Serialization, JSON, and Distributed Systems
Working with a teammate who was running into an error recently when testing their work in the staging environment, that they hadn’t seen when developing locally. This was the error they were seeing:
TypeError: <Object> is not JSON serializable
But, “I’m not calling json.dumps()
on anything!” they said. And sure enough, they weren’t. But they were enqueueing background tasks, which, when developing locally happen in the foreground without ever being enqueued. This the first hint to the difference between the two environments, and where the serialization was happening.
But first, let’s define our terms.
Serialization
Serialization is the process of turning data structures into another format that can be stored or transmitted over the network.
Examples of serialization formats include JSON, XML, and YAML, so the process of turning any data type into one of these formats is called “serialization. ”
Spoiler alert: In this case, what we’re looking at is the attempt to turn an object returned from the Django ORM into JSON.
JSON
JSON is one of the most common ways of formatting data for sending over the network. It stands for JavaScript Object Notation, because…