My first thought was serialize(...)that I'm "serializing" the complex object, but from what I understand that makes me feel likemeans I'm reducing it down to a string or binary format which cancould be passed over a network. While what I am actually doing is converting a complex object to more primitive types like list, dict, str, int, float, etc. (TheThe context here is python), and I'm trying to rename my function to_dict(...) to something which uses a more idiomatic/industry accepted term.
Currently I'm doing this:
class SomeComplexClass:
...
my_complex_obj = SomeComplexClass(...)
simple_obj = to_dict(my_complex_obj)
simple_obj['foo'] = 'bar'
return to_json(simple_obj)
As you see, I'll typically do some final adjustments to the object, then pass this to a library which knows how to convert this into a JSON string, which is passed over the network as HTTP response. This function is used 608 times in our code base.
Here to_dict(...) is doing some heavy lifting, by recursively walking through the complex object and handling corner cases etc., it even supports multiple types of complex objects, even lists of objects.
It is this last part which makes me question the name to_dict(...), because I at some time extended it to support lists as the top level object type. It feels a little silly to do list_of_simple_objects = to_dict(my_list_of_complex_objects), because it then returns a list of dicts.
What are some good alternatives for naming to_dict(...)?