View Source Jsonrs (jsonrs v0.3.4)
A JSON library powered by Rust's Serde through a NIF
Summary
Functions
Parses a JSON value from input
string.
Parses a JSON value from input
string.
Generates JSON corresponding to input
.
Generates JSON corresponding to input
.
Identical to encode/1
. Exists to implement Phoenix interface and encodes to a single normal string.
Identical to encode!/1
. Exists to implement Phoenix interface and encodes to a single normal string.
Types
@type compression_algorithm() :: :gzip | :none
@type compression_level() :: non_neg_integer()
@type compression_options() :: {compression_algorithm(), compression_level()}
Functions
Parses a JSON value from input
string.
Examples
iex> Jsonrs.decode("{\"x\":[1,2]}")
{:ok, %{"x" => [1, 2]}}
iex> Jsonrs.decode("invalid")
{:error, "expected value at line 1 column 1"}
Parses a JSON value from input
string.
Similar to decode/2
except it will raise in case of errors.
Examples
iex> Jsonrs.decode!("{\"x\":[1,2]}")
%{"x" => [1, 2]}
iex> Jsonrs.decode!("invalid")
** (ErlangError) Erlang error: "expected value at line 1 column 1"
Generates JSON corresponding to input
.
Examples
iex> Jsonrs.encode(%{"x" => [1,2]})
{:ok, "{\"x\":[1,2]}"}
iex> Jsonrs.encode("\xFF")
{:error, "Expected to deserialize a UTF-8 stringable term"}
Generates JSON corresponding to input
.
Similar to encode/1
except it will raise in case of errors.
Examples
iex> Jsonrs.encode!(%{"x" => [1,2]})
"{\"x\":[1,2]}"
iex> Jsonrs.encode!("\xFF")
** (ErlangError) Erlang error: "Expected to deserialize a UTF-8 stringable term"
Identical to encode/1
. Exists to implement Phoenix interface and encodes to a single normal string.
Identical to encode!/1
. Exists to implement Phoenix interface and encodes to a single normal string.