Module Jsonxt.Extended_stream
Extended_stream
supports parsing and writing JSON data that conforms to the Json_stream.Extended.json
type as a stream of Json_stream.Extended.json
objects. This supports non-standard JSON types including integer as well as tuples and variants introduced by Yojson
type json_stream
= Json_stream.Extended.json
Reader functions
include Jsonxt__.Reader_stream.Reader_stream with type json_stream := json_stream
json_stream_* and decode functions
val json_stream_of_string : string -> stream
json_stream_of_string s
creates a stream parser that returns a series ofjson_stream
elements from the strings
.
val json_stream_of_channel : Stdlib.in_channel -> stream
json_stream_of_channel ic
creates a stream parser that returns a series ofjson_stream
elements from thein_channel
ic
.
val json_stream_of_function : (bytes -> int -> int) -> stream
json_stream_of_function f
creates a stream parser that returns a series ofjson_stream
elements from the reader functionf
.f buf len
takes a bufferbuf
and maximum lengthlen
and returns the number of bytes read to a maximum oflen
val decode_stream : stream -> (json_stream option, string) Stdlib.result
decode_stream t
decode the next element of the input,Ok None
indicates end of the stream
Stream.t
functions
These functions provide a Stream.t
API on top of the json_stream_of_* and decode_stream functions.
val stream_from_string : string -> json_stream Stdlib.Stream.t
stream_from_string s
creates ajson_stream Stream.t
fromjson_stream_of_string s
anddecode_stream
val stream_from_channel : Stdlib.in_channel -> json_stream Stdlib.Stream.t
stream_from_channel ic
creates ajson_stream Stream.t
fromjson_stream_of_channel ic
anddecode_stream
val stream_from_function : (bytes -> int -> int) -> json_stream Stdlib.Stream.t
stream_from_function f
creates ajson_stream Stream.t
fromjson_stream_of_function f
anddecode_stream
Writer functions
include Jsonxt__.Writer_stream_intf.Intf with type json_stream := json_stream
val create_encoder' : add_char:(char -> unit) -> add_string:(string -> unit) -> incr:int -> eol:string -> t
create_encoder' ~add_char ~add_string ~incr ~eol
is the low level function used to create the various stream encoders. Theadd_char c
andadd_string s
functions handle adding achar
c
andstring
s
to the output respectively.incr
andeol
work together to output human readable output.incr
defines the increase in indentation andeol
the end of line sequence. A typet
is returned
val create_encoder : add_char:(char -> unit) -> add_string:(string -> unit) -> t
create_encoder ~add_char ~add_string
creates a compact encoder.add_char
andadd_string
add achar
andstring
to the output respectively A typet
is returned
val create_encoder_hum : add_char:(char -> unit) -> add_string:(string -> unit) -> t
create_encoder_hum ~add_char ~add_string
creates a human readable encoder.add_char
andadd_string
add achar
andstring
to the output respectively. The increment is set to 2 and end of line to LF (\n). A typet
is returned
val create_encoder_channel : Stdlib.out_channel -> t
create_encoder_channel oc
creates a compact encoder outputing to channeloc
val create_encoder_channel_hum : Stdlib.out_channel -> t
create_encoder_channel_hum oc
creates a human readable encoder outputing to channeloc
val encode_stream_exn : t -> json_stream -> unit
encode_stream_exn t json_stream
encodes and outputs the elementjson_stream
. Errors cause a Failure exception to be raised.
val encode_stream : t -> json_stream -> (unit, string) Stdlib.result
encode_stream_exn t json_stream
encodes and outputs the elementjson_stream
. Errors are reported via theresult
value.