What is the way to convert %{\"foo\" => \"bar\"}
to %{foo: \"bar\"}
in Elixir?
You can use a combination of Enum.reduce/3 and String.to_atom/1
%{"foo" => "bar"}
|> Enum.reduce(%{}, fn ({key, val}, acc) -> Map.put(acc, String.to_atom(key), val) end)
However you should be wary of converting to atoms based in user input as they will not be garbage collected which can lead to a memory leak. See this issue.
You can use String.to_existing_atom/1 to prevent this if the atom already exists.