Confispex.Type.JSON (confispex v1.1.0)

A JSON type.

Casts JSON string to Elixir terms using Jason library.

Options

  • :keys - possible values are: :strings (default), :atoms, :atoms!. Read about meaning of this values in doc for Jason.decode/2.

Examples

iex> Confispex.Type.cast(~s|[{"email":"john@example.com","level":1}]|, Confispex.Type.JSON)
{:ok, [%{"email" => "john@example.com", "level" => 1}]}

iex> Confispex.Type.cast(~s|[{"email":"john@example.com","level":1}]|, {Confispex.Type.JSON, keys: :atoms})
{:ok, [%{email: "john@example.com", level: 1}]}

iex> Confispex.Type.cast("", Confispex.Type.JSON)
{:error, {"", Confispex.Type.JSON, [parsing: "unexpected end of input at position 0"]}}