>>> def encode_complex(obj):
...     if isinstance(obj, complex):
...         return [obj.real, obj.imag]
...     raise TypeError(f'Object of type {obj.__class__.__name__} '
...                     f'is not JSON serializable')
...