In this video you’ll learn how to work with types that are non-serializable.
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.
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
dumps() methods. In the next video, you’ll learn how to encode them into JSON format.