FlattenMap (flatten_map v0.1.1) View Source

Documentation for FlattenMap.

Motivation

The motivating use case for this module is to flatten nested JSON data. Thus, the library assumes all keys are strings and will convert any non-string keys to strings. If the map key cannot be converted to a string, the function will fail.

Maps are flattened by concatenating keys together.

Link to this section Summary

Functions

Flattens an arbitrarily deep map.

Link to this section Functions

Link to this function

flatten(m, delimeter \\ ".")

View Source

Flattens an arbitrarily deep map.

Examples

iex> %{a: 1} |> FlattenMap.flatten()
%{"a" => 1}

iex> %{a: %{b: 1, c: 2}} |> FlattenMap.flatten()
%{"a.b" => 1, "a.c" => 2}

iex> %{"a" => %{b: %{c: %{d: :end}}}} |> FlattenMap.flatten()
%{"a.b.c.d" => :end}