def object_to_primitive(obj):
if obj is None:<EOL><INDENT>return obj<EOL><DEDENT>if isinstance(obj, (int, float, bool, str)):<EOL><INDENT>return obj<EOL><DEDENT>if isinstance(obj, (list, frozenset, set)):<EOL><INDENT>return [object_to_primitive(x) for x in obj]<EOL><DEDENT>if isinstance(obj, dict):<EOL><INDENT>return dict([(object_to_primitive(k), object_to_primitive(v)) for k, v in obj.items()])<EOL><DEDENT>data = vars(obj)<EOL>assert isinstance(data, dict)<EOL>return object_to_primitive(data)<EOL>
convert object to primitive type so we can serialize it to data format like python.

all primitive types: dict, list, int, float, bool, str, None