ExWapp.JSON (ExWapp v0.1.2)

Copy Markdown View Source

Configurable JSON boundary used by ExWapp.

ExWapp deliberately does not depend on a JSON implementation. The host application must provide a module exposing encode/1 and decode/1 with the conventional {:ok, value} | {:error, reason} return shape:

config :ex_wapp, :json_library, Jason

Jason, Poison, Elixir's JSON module, or a small adapter around another implementation can be used. Modules exposing only the bang variants are supported too.

Summary

Functions

Decodes JSON with the configured JSON implementation.

Decodes JSON or raises when JSON is unavailable or decoding fails.

Encodes a value with the configured JSON implementation.

Encodes a value or raises when JSON is unavailable or encoding fails.

Returns the JSON module configured by the host application.

Types

error_reason()

@type error_reason() ::
  :json_library_not_configured
  | {:invalid_json_library, term()}
  | {:invalid_json_library_response, :encode | :decode, term()}
  | term()

Functions

decode(value)

@spec decode(iodata()) :: {:ok, term()} | {:error, error_reason()}

Decodes JSON with the configured JSON implementation.

decode!(value)

@spec decode!(iodata()) :: term() | no_return()

Decodes JSON or raises when JSON is unavailable or decoding fails.

encode(value)

@spec encode(term()) :: {:ok, binary()} | {:error, error_reason()}

Encodes a value with the configured JSON implementation.

encode!(value)

@spec encode!(term()) :: binary() | no_return()

Encodes a value or raises when JSON is unavailable or encoding fails.

library()

@spec library() :: {:ok, module()} | {:error, error_reason()}

Returns the JSON module configured by the host application.