def convert_ids_to_object_ids(obj_map):
converted_map = {}<EOL>for key, value in obj_map.items():<EOL><INDENT>if key == '<STR_LIT>':<EOL><INDENT>try:<EOL><INDENT>converted_map[key] = ObjectId(value)<EOL><DEDENT>except InvalidId:<EOL><INDENT>converted_map[key] = value<EOL><DEDENT><DEDENT>elif isinstance(value, dict):<EOL><INDENT>converted_map[key] = convert_ids_to_object_ids(value)<EOL><DEDENT>elif isinstance(value, list):<EOL><INDENT>new_list = []<EOL>for internal_item in value:<EOL><INDENT>if isinstance(internal_item, dict):<EOL><INDENT>new_list.append(convert_ids_to_object_ids(internal_item))<EOL><DEDENT>else:<EOL><INDENT>new_list.append(internal_item)<EOL><DEDENT><DEDENT>converted_map[key] = new_list<EOL><DEDENT>else:<EOL><INDENT>converted_map[key] = value<EOL><DEDENT><DEDENT>return converted_map<EOL>
converts string representations of _id back to ObjectId obj