Library
Module
Module type
Parameter
Class
Class type
Extended
supports parsing and writing JSON data that conforms to the Json.Extended.json
json type. This supports non-standard JSON types including integer as well as tuples and variants introduced by Yojson
.
The maximim/minimum size of an integer is architecture specific, typically 30 or 62 bits depending on the platform. In cases where the integer overflows the value is converted to a `Float. For integers in the range (+/-)2^53 there is no loss of precision
type json = Json.Extended.json
type t = json
Reader_string_file
supports functions to parse JSON data from various sources. The interface includes two type of parser
json Stream.t
functions that process a stream of JSON data, possibly seperated by whitespace. eg. {"a": 1} {"b":2}
would result in 2 Json values being returned by the streamjson_of_string string
converts string
to a json
value returing an error if the string has syntax, grammar or compliance errors
val json_of_string_exn : string -> json
json_of_string_exn string
converts string
to a json
value raising a Failure
exception if the string has syntax, grammar or compliance errors
json_of_file file
converts the text from file
to a json
value returing an error if the file contents have syntax, grammar or compliance errors. The file is closed on error
val json_of_file_exn : string -> json
json_of_file file
converts the text from file
to a json
value raising a Failure
exception if the file contents have syntax, grammar or compliance errors. The file is closed on error
val json_of_channel : in_channel -> (json, string) result
json_of_channel channel
converts the text from channel
to a json
value returing an error if the channel contents have syntax, grammar or compliance errors. The channel is not closed
val json_of_channel_exn : in_channel -> json
json_of_channel channel
converts the text from channel
to a json
value raising a Failure
exception if the channel contents have syntax, grammar or compliance errors. The file is not closed
json_of_function f
converts text provided by f
to a json
value returing an error if the supplied text has syntax, grammar or compliance errors. The function f buf len
takes a bytes
buf
buffer, the maximum number of bytes to read len
and returns the number of bytes read. Returning 0 indicates end-of-file
val json_of_function_exn : (bytes -> int -> int) -> json
json_of_function_exn f
converts text provided by f
to a json
value raising a Failure
exception if the channel contents have syntax, grammar or compliance errors. See json_of_function
for detail of function f
val json_of_lexbuf : Lexing.lexbuf -> (json, string) result
json_of_lexbuf lexbuf
converts text in the supplied lexbuf
to a json
value returning an error if the supplied text has syntax, grammar or compliance errors. This is a low level function and json_of_function should be used in preference
val json_of_lexbuf_exn : Lexing.lexbuf -> json
json_of_lexbuf_exn lexbuf
converts text in the supplied lexbuf
to a json
value raising a Failure
exception if the supplied text has syntax, grammar or compliance errors. This is a low level function and json_of_function_exn should be used in preference
val of_string : string -> json
of_string
is an alias for json_of_string_exn
val of_file : string -> json
of_file
is an alias for json_of_file_exn
val of_channel : in_channel -> json
of_channel
is an alias for json_of_channel_exn
val of_function : (bytes -> int -> int) -> json
of_function
is an alias for json_of_function_exn
The following functions are identical to the functions without the _error_info extension except they return an (json, Error_info.t) result
instead of a (json, string) result
. See Jsonxt.Error_info
for details of of Error_info.t
val json_of_string_error_info : string -> (json, Error_info.t) result
val json_of_file_error_info : string -> (json, Error_info.t) result
val json_of_channel_error_info : in_channel -> (json, Error_info.t) result
val json_of_function_error_info :
(bytes -> int -> int) ->
(json, Error_info.t) result
val json_of_lexbuf_error_info : Lexing.lexbuf -> (json, Error_info.t) result
val json_of_lexbuf_error_info_compat :
?stream:bool ->
Lexing.lexbuf ->
(json option, Error_info.t) result
Stream.t
readersStream.t
readers provide a mechanism to read a stream of JSON values. eg
{"datapoint": 1, "value": 2}
{"datapoint": 2, "value": 5}
stream_from_string string
converts string
containing zero or more json object to a json Stream.t
value raising a Failure
exception if the string has syntax, grammar or compliance errors
val stream_from_channel : ?fin:(unit -> unit) -> in_channel -> json Stream.t
stream_from_channel in_channel
converts the text from in_channel
, containing zero or more json objects, to a json Stream.t
value raising a Failure
exception if the file has syntax, grammar or compliance errors. The optional parameter fin
specifies a function to call when all json objects have been returned or a failure occurs
stream_from_file filename
converts the text from file filename
, containing zero or more json objects, to a json Stream.t
value raising a Failure
exception if the file has syntax, grammar or compliance errors
stream_from_function f
converts text provided by f
, containing zero of more JSON objects, to a json Stream.t
value raising a Failure
exception if the file has syntax, grammar or compliance errors. The function f buf len
takes a buf
buffer to fill, the maximum number of bytes to read len
and returns the number of bytes read. Returning 0 indicates end-of-file
val stream_from_lexbuf : Lexing.lexbuf -> json Stream.t
stream_from_file lexbuf
converts the text from lexbuf
, containing zero or more json objects, to a json Stream.t
value raising a Failure
exception if the file has syntax, grammar or compliance errors. This is a low level function and stream_from_function should be used in preference
The following functions are identical to the functions without the _error_info extension except they raise an Error_info.Json_error_info Error_info.t
exception instead of a Failure string
. See Jsonxt.Error_info
for details of the exception
val stream_from_channel_error_info :
?fin:(unit -> unit) ->
in_channel ->
json Stream.t
val stream_from_lexbuf_error_info : Lexing.lexbuf -> json Stream.t
val json_to_string : Json.Extended.json -> (string, string) result
json_to_string json
converts json
to a string
, returning an error if the json value contains data that fails compliance checks
val json_to_string_exn : Json.Extended.json -> string
json_to_string_exn json
converts json
to a string
, raising a Failure
excepion if the json value contains data that fails compliance checks
val to_string : Json.Extended.json -> string
to_string
is an alias for json_to_string_exn
val json_to_string_hum : Json.Extended.json -> (string, string) result
json_to_string_hum json
converts json
to a string
in human readable format, returning an error if the json value contains data that fails compliance checks
val json_to_string_hum_exn : Json.Extended.json -> string
json_to_string_hum_exn json
converts json
to a string
in human readable format, raising a Failure
excepion if the json value contains data that fails compliance checks
val to_string_hum : Json.Extended.json -> string
to_string_hum
is an alias for json_to_string_hum_exn
val json_to_file : string -> Json.Extended.json -> (unit, string) result
json_to_file file json
converts json
to a string and writes it to file
, returning an error if the json value contains data that fails compliance checks. The file will be closed on error.
val json_to_file_hum : string -> Json.Extended.json -> (unit, string) result
json_to_file_hum file json
converts json
to a string in human readable format and writes it to file
, returning an error if the json value contains data that fails compliance checks. The file will be closed on error.
val json_to_file_exn : string -> Json.Extended.json -> unit
json_to_file_exn file json
converts json
to a string and writes it to file
, raising a Failure
exception if the json value contains data that fails compliance checks. The file will be closed on error.
val json_to_file_hum_exn : string -> Json.Extended.json -> unit
json_to_file_hum_exn file json
converts json
to a string in human readable format and writes it to file
, raising Failure
exception if the json value contains data that fails compliance checks. The file will be closed on error.
val json_to_channel :
out_channel ->
Json.Extended.json ->
(unit, string) result
json_to_channel channel json
converts json
to a string and writes it to channel
, returning an error if the json value contains data that fails compliance checks. The channel is not closed.
val json_to_channel_exn : out_channel -> Json.Extended.json -> unit
json_to_channel_exn channel json
converts json
to a string and writes it to channel
, raising a Failure
exception if the json value contains data that fails compliance checks. The channel will be closed on error.
val json_to_channel_hum :
out_channel ->
Json.Extended.json ->
(unit, string) result
json_to_channel_hum channel json
converts json
to a string in human readable format and writes it to channel
, returning an error if the json value contains data that fails compliance checks. The channel is not closed.
val json_to_channel_hum_exn : out_channel -> Json.Extended.json -> unit
json_to_channel_hum_exn channel json
converts json
to a string in human readable format and writes it to channel
, raising Failure
exception if the json value contains data that fails compliance checks. The channel is not closed
val to_file : string -> Json.Extended.json -> unit
to_file
is an alias for json_to_file_exn
val to_file_hum : string -> Json.Extended.json -> unit
to_file_hum
is an alias for json_to_file_hum_exn
val to_channel : out_channel -> Json.Extended.json -> unit
to_channel
is an alias for json_to_channel_exn
val to_channel_hum : out_channel -> Json.Extended.json -> unit
to_channel_hum
is an alias for json_to_channel_hum_exn
val json_to_buffer : Buffer.t -> Json.Extended.json -> (unit, string) result
json_to_buffer buf json
converts and outputs json
to the supplied buf
, returning an error if the json value contains data that fails compliance checks.
val json_to_buffer_exn : Buffer.t -> Json.Extended.json -> unit
json_to_buffer_exn buf json
converts and outputs json
to the supplied buf
, raising a Failure
exception if the json value contains data that fails compliance checks.
val json_to_buffer_hum :
Buffer.t ->
Json.Extended.json ->
(unit, string) result
json_to_buffer_hum buf json
converts and outputs json
in a human readable format to the supplied buf
, returning an eror if the json value contains data that fails compliance checks.
val json_to_buffer_hum_exn : Buffer.t -> Json.Extended.json -> unit
json_to_buffer_hum_exn buf json
converts and outputs json
in a human readable format to the supplied buf
, raising a Failure
exception if the json value contains data that fails compliance checks.
val to_buffer : Buffer.t -> Json.Extended.json -> unit
to_buffer
is an alias for json_to_buffer_exn
val to_buffer_hum : Buffer.t -> Json.Extended.json -> unit
to_buffer_hum
is an alias for json_to_buffer_hum_exn
val pretty_print : Format.formatter -> Json.Extended.json -> unit
pretty_print out json
pretty prints the json
tree to the Formater.formatter
The output is more compact than the _hum versions but still readable
val pretty_print_to_string : Json.Extended.json -> string
pretty_print_to_string json
converts the json
tree into a pretty printed string. The output is more compact than the _hum versions but still readable
val pretty_print_to_channel : out_channel -> Json.Extended.json -> unit
pretty_print oc json
pretty prints the json
tree to the output channel out
The output is more compact than the _hum versions but still readable
val stream_to_string : Json.Extended.json Stream.t -> string
stream_to_string stream
converts a Stream.t
of json
values to a string, separating the enties with newlines
val stream_to_channel : out_channel -> Json.Extended.json Stream.t -> unit
stream_to_channel out_channel
converts a Stream.t
of json
values to a newline separated list of compact json strings and outputs them to out_channel
val stream_to_file : string -> Json.Extended.json Stream.t -> unit
stream_to_file stream file
converts a Stream.t
of json
values to a newline separated list of compact json strings and outputs them to file
val stream_to_buffer : Buffer.t -> Json.Extended.json Stream.t -> unit
stream_to_buffer buf stream
converts a Stream.t
of json
values to compact strings and outputs them, separating by newlines, to buf
module Process : sig ... end
module Compliance : sig ... end