Use the Map.from_struct function.

struct = %User{first_name: "Jose", last_name: "Valim"}
map = Map.form_struct(struct)