Jaxon v0.1.1 Jaxon View Source

Example

Create a new decoder and add your JSON data:

decoder =
  Jaxon.make_decoder()
  |> Jaxon.update_decoder("{\"jaxon\":\"rocks\",\"array\":[1,2]}")

Call decode/1 on the decoder to consume the events one by one:

iex> decoder = Jaxon.make_decoder() |> Jaxon.update_decoder("{\"jaxon\":\"rocks\",\"array\":[1,2]}")
iex> Jaxon.decode(decoder)
:start_object

Or call consume/1 to read all the events in a list:

iex> decoder = Jaxon.make_decoder() |> Jaxon.update_decoder("{\"jaxon\":\"rocks\",\"array\":[1,2]}")
iex> Jaxon.consume(decoder)
[
 :start_object,
 {:key, "jaxon"},
 {:string, "rocks"},
 {:key, "array"},
 :start_array,
 {:integer, 1},
 {:integer, 2},
 :end_array,
 :end_object,
 :end
]

Link to this section Summary

Functions

Helper function that calls decode/1 until there are no more events

Get a single event from the decoder, must call update_decoder/2 with your data beforehand

Link to this section Types

Link to this type event() View Source
event() ::
  :start_object
  | :end_object
  | :start_array
  | :end_array
  | {:key, binary()}
  | {:string, binary()}
  | {:integer, integer()}
  | {:decimal, float()}
  | {:boolean, boolean()}
  | nil
  | {:incomplete, binary()}
  | :end
  | :error

Link to this section Functions

Link to this function consume(decoder) View Source
consume(decoder()) :: [event()]

Helper function that calls decode/1 until there are no more events.

Example

iex> Jaxon.make_decoder() |> Jaxon.update_decoder(“{\”jaxon\”:\”rocks\”}”) |> Jaxon.consume() [:start_object, {:key, “jaxon”}, {:string, “rocks”}, :end_object, :end]

Get a single event from the decoder, must call update_decoder/2 with your data beforehand.

Example

iex> Jaxon.make_decoder() |> Jaxon.update_decoder(“{\”jaxon\”:\”rocks\”}”) |> Jaxon.decode() :start_object

Link to this function make_decoder() View Source
make_decoder() :: decoder()
Link to this function update_decoder(_, _) View Source
update_decoder(decoder(), binary()) :: decoder()