UnsafeAtomizeKeys (unsafe_atomize_keys v1.1.0)

Link to this section Summary

Functions

Function to convert all binary keys to atoms in a map. Keys of other types will be left unchanged. The conversion will deeply traverse nested maps and lists. See README for explanation of why this function is "unsafe".

Link to this section Functions

Link to this function

unsafe_atomize_keys(map, func \\ &Function.identity/1)

Function to convert all binary keys to atoms in a map. Keys of other types will be left unchanged. The conversion will deeply traverse nested maps and lists. See README for explanation of why this function is "unsafe".

The optional func argument is a function that accepts a string and performs some kind of transformation on that string.

examples

Examples

iex> unsafe_atomize_keys(%{"a" => "b", :c => "d"}) %{a: "b", c: "d"}

iex> unsafe_atomize_keys(%{"deep" => %{"key" => "value"}}) %{deep: %{key: "value"}}

iex> unsafe_atomize_keys(%{"list" => [%{"key" => "value"}]}) %{list: [%{key: "value"}]}

iex> unsafe_atomize_keys(%{"theKey" => "b", :c => "d"}, &Macro.underscore/1) %{the_key: "b", c: "d"}