View Source JsonStreamEncoder (json_stream_encoder v0.2.0)
Primary API for encoding streaming JSON documents.
Link to this section Summary
Functions
Encode an array into the stream, using the contents of the function to set elements.
End an array you previously started encoding with ary_start/1
.
Start encoding an array. Always pair with ary_end/1
.
Encode a key for an object.
Encode a key-value pair for an object.
Create a new streamer without indentation.
Create a new streamer with the given indentation settings.
Encode an object into the stream, using the contents of the function to set key/value pairs.
End an object you previously started encoding with obj_start/1
.
Start encoding an object. Always pair with obj_end/1
.
Encode a value.
Link to this section Types
Specs
encodeable() :: Jason.Encoder.t()
Specs
Specs
io_stream() :: IO.device()
Specs
key() :: atom() | binary() | number() | nonempty_charlist() | boolean()
Specs
streamer()
Link to this section Functions
Specs
Encode an array into the stream, using the contents of the function to set elements.
examples
Examples
ary(streamer, fn(stream) ->
stream |> val(1) |> val("2")
end)
#=> [1,"2"]
Specs
End an array you previously started encoding with ary_start/1
.
Specs
Start encoding an array. Always pair with ary_end/1
.
More often you will want to use ary/2
.
examples
Examples
streamer |> ary_start() |> val(1) |> val("2") |> ary_end()
#=> [1,"2"]
Specs
Encode a key for an object.
Always follow this with a val/2
, obj/2
, or ary/2
- otherwise your JSON won't make any sense.
Specs
kv(streamer(), key(), encodeable()) :: streamer()
Encode a key-value pair for an object.
You should really only use this if your value is simple, otherwise use key/2
in combination with other functions.
Specs
Create a new streamer without indentation.
Specs
new(io_stream(), indentation()) :: streamer()
Create a new streamer with the given indentation settings.
Pass false
for no indentation, true
for default indentation (two spaces), or
a binary
representing the desired indentation string.
Specs
Encode an object into the stream, using the contents of the function to set key/value pairs.
examples
Examples
obj(streamer, fn(stream) ->
stream |> kv(1,"2")
end)
#=> {"1": "2"}
Specs
End an object you previously started encoding with obj_start/1
.
Specs
Start encoding an object. Always pair with obj_end/1
.
More often you will want to use obj/2
.
examples
Examples
streamer |> obj_start() |> kv(1,"2") |> obj_end()
#=> {"1": "2"}
Specs
val(streamer(), encodeable()) :: streamer()
Encode a value.
Usable anywhere you would expect a JSON value:
- The root of a document
- After a key
- As an array element