serialize#

serialize(obj: Any) Any#

Recursively expand an object into JSON-serializable primitives, by applying __serialize__() to objects that define it.

Similar in spirit to dataclasses.asdict(), but uses the library’s serialization protocol and preserves the “__type__” tag so the result can be round-tripped with object_hook/__deserialize__.

Returns#

Any
A structure composed only of:
  • dict[str, Any]

  • list[Any]

  • str/int/float/bool/None