In this video you’ll learn how to work with types that are non-serializable.
The json
module is not capable of serializing all Python types. Non-serializable types include custom types created from classes, as well as the built-in complex
type used to represent imaginary numbers.
json_str = json.dumps(6 + 2j) # cannot serialize complex object
In order to serialize these types, we must extract the necessary data to recreate the object.
The complex
type stores both the real and imaginary parts of the complex number as float
. Floats are a type that can be serialized by the dump()
and dumps()
methods. In the next video, you’ll learn how to encode them into JSON format.
terrymiddleton on May 11, 2019
So…after a little Google searching on serialize and deserialize of json, it has become apparent that the process of serializing and deserializing is simply taking a json object and converting it to a string that can be worked with.
Is this correct.
With an object, it has a certain structure and framework that does not work well/properly with evaluating or working with strings. An output to a file has to be put in a string format so it can be written, while the data may reside in an object.
For example, if I wanted to write out all the books in a certain library and all the books were sitting in an object called library, I would need to “convert” all the books within the object to a string so I could write it to a file or work with it in code.
Am I thinking correctly on this? Terry