json v1.3.0 JSON.Encoder protocol View Source
Defines the protocol required for converting Elixir types into JSON and inferring their json types.
Link to this section Summary
Functions
Returns a JSON string representation of the Elixir term
Returns an atom that reprsents the JSON type for the term
Link to this section Types
Link to this type
t()
View Source
t()
View Source
t() :: term()
t() :: term()
Link to this section Functions
Link to this function
encode(term) View Source
Returns a JSON string representation of the Elixir term
Examples
iex> JSON.Encoder.encode({1, :two, "three"})
{:ok, "[1,\"two\",\"three\"]"}
iex> JSON.Encoder.encode([result: "this will be a elixir result"])
{:ok, "{\"result\":\"this will be a elixir result\"}"}
iex> JSON.Encoder.encode(%{a: 1, b: 2})
{:ok, "{\"a\":1,\"b\":2}"}
Link to this function
typeof(term) View Source
Returns an atom that reprsents the JSON type for the term
Examples
iex> JSON.Encoder.typeof(3)
:number
iex> JSON.Encoder.typeof({1, :two, "three"})
:array
iex> JSON.Encoder.typeof([foo: "this will be a elixir result"])
:object
iex> JSON.Encoder.typeof([result: "this will be a elixir result"])
:object
iex> JSON.Encoder.typeof(["this will be a elixir result"])
:array
iex> JSON.Encoder.typeof([foo: "bar"])
:object