JViewer (JViewer v0.1.5) View Source

JViewer is an excellent way to declaratively represent elixir data in a JSON encodable format.

Link to this section Summary

Link to this section Types

Link to this section Functions

Specs

array(keyword()) :: struct()

Specs

boolean(keyword()) :: struct()

Specs

field(keyword()) :: struct()

Specs

number(keyword()) :: struct()

Specs

object(keyword()) :: struct()
Link to this function

represent(data, schema, general_handlers_params \\ %{})

View Source

Specs

represent(map(), schema(), any()) :: map()

Represents data in a JSON encodable format according to schema.

If data cannot be represented, an exception is thrown.

Example

iex> import JViewer
...>
iex> schema =
iex>   object(
iex>     fields: [
iex>       field(
iex>         key: "id",
iex>         type: number()
iex>       ),
iex>       field(
iex>         key: "title",
iex>         type: string()
iex>       )
iex>     ]
iex>   )
...>
iex> data = %{
iex>   id: 1,
iex>   info: "I ate bread for breakfast",
iex>   title: "Notes"
iex> }
...>
iex> represent(data, schema)
%{
  "id" => 1,
  "title" => "Notes"
}

Specs

string(keyword()) :: struct()