StrapiMapper (strapi_mapper v0.2.0)
StrapiMapper is a library for mapping Strapi responses to Elixir maps. It doesn't care which JSON library you use, it just needs a map as input.
Summary
Functions
Maps a Strapi response map to a normalized Elixir map.
Functions
Link to this function
map_to_struct(data, options \\ %StrapiMapper.Options{})
@spec map_to_struct(data :: any(), options :: StrapiMapper.Options.t()) :: map()
Maps a Strapi response map to a normalized Elixir map.
If the input data is a list, it will map each element of the list.
If the input data is a map, it will map each key-value pair of the map.
Otherwise, it will return the input data.
Example
iex> StrapiMapper.map_to_struct(%{"data" => %{"id" => 1, "attributes" => %{"name" => "John"}}})
%{"id" => 1, "name" => "John"}
iex> StrapiMapper.map_to_struct(%{"data" => %{"id" => 1, "attributes" => %{"name" => "Jane"}}}, %StrapiMapper.Options{keys_returned_as: :atoms})
%{id: 1, name: "Jane"}