json v1.1.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 section Functions

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}"}

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