What is the way to convert %{\"foo\" => \"bar\"}
to %{foo: \"bar\"}
in Elixir?
To build on @emaillenin's answer, you can check to see if the keys are already atoms, to avoid the ArgumentError
that is raised by String.to_atom when it gets a key that is already an atom.
for {key, val} <- string_key_map, into: %{} do
cond do
is_atom(key) -> {key, val}
true -> {String.to_atom(key), val}
end
end