JSON (json v1.4.1) View Source

Provides a RFC 7159, ECMA 404, and JSONTestSuite compliant JSON Encoder / Decoder

Link to this section Summary

Functions

Converts a valid JSON string into an Elixir term

Converts a valid JSON string into an Elixir term, raises errors when something bad happens

Returns a JSON string representation of the Elixir term

Returns a JSON string representation of the Elixir term, raises errors when something bad happens

Link to this section Functions

Link to this function

decode(bitstring_or_char_list)

View Source

Specs

decode(bitstring()) :: {atom(), term()}
decode(charlist()) :: {atom(), term()}

Converts a valid JSON string into an Elixir term

Examples

iex> JSON.decode("{\"result\":\"this will be an Elixir result\"}")
{:ok, Enum.into([{"result", "this will be an Elixir result"}], Map.new)}
Link to this function

decode!(bitstring_or_char_list)

View Source

Specs

decode!(bitstring()) :: term()
decode!(charlist()) :: term()

Converts a valid JSON string into an Elixir term, raises errors when something bad happens

Examples

iex> JSON.decode!("{\"result\":\"this will be an Elixir result\"}")
Enum.into([{"result", "this will be an Elixir result"}], Map.new)

Specs

encode(term()) :: {atom(), bitstring()}

Returns a JSON string representation of the Elixir term

Examples

iex> JSON.encode([result: "this will be a JSON result"])
{:ok, "{\"result\":\"this will be a JSON result\"}"}

Specs

encode!(term()) :: bitstring()

Returns a JSON string representation of the Elixir term, raises errors when something bad happens

Examples

iex> JSON.encode!([result: "this will be a JSON result"])
"{\"result\":\"this will be a JSON result\"}"