The JSON boundary shared with the Absurd PostgreSQL schema.
Absurd stores protocol values in JSONB. Consequently, arbitrary Elixir terms, structs, tuples, atom map keys, and ETF values are rejected before a query is issued.
Examples
iex> Absurd.JSON.valid?(%{"name" => "Ada", "attempt" => 1})
true
iex> match?({:error, %Absurd.Error{kind: :validation}}, Absurd.JSON.validate(%{name: "Ada"}))
true
iex> Absurd.JSON.encode([true, nil, 3])
{:ok, "[true,null,3]"}
Summary
Types
A scalar accepted by JSON and PostgreSQL JSONB.
A recursively JSON-compatible Elixir value with binary object keys.
Functions
Validates and encodes a protocol value with Jason.
Returns whether value can cross the protocol JSON boundary.
Validates a protocol value.
Types
Functions
@spec encode(term()) :: {:ok, String.t()} | {:error, Absurd.Error.t()}
Validates and encodes a protocol value with Jason.
Returns whether value can cross the protocol JSON boundary.
@spec validate(term()) :: :ok | {:error, Absurd.Error.t()}
Validates a protocol value.
Returns an Absurd.Error describing the first invalid value and its path.