package jsont
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha512=6206f73a66cb170b560a72e58f70b9fb2c20397b9ab819dceba49b6602b9b79e47ba307e6910e61ca4694555c66fdcd7a17490afb99548e8f43845a5a88913e7
doc/jsont.bytesrw/Jsont_bytesrw/index.html
Module Jsont_bytesrwSource
JSON codec.
According to RFC 8259.
See notes about layout preservation and behaviour on duplicate members.
Tip. For maximal performance decode with ~layout:false and ~locs:false, this is the default. Howver using ~locs:true improves some error reports.
Decode
val decode :
?layout:bool ->
?locs:bool ->
?file:Jsont.Textloc.fpath ->
'a Jsont.t ->
Bytesrw.Bytes.Reader.t ->
('a, string) resultdecode t r decodes a value from r according to t.
- If
layoutistruewhitespace is preserved inJsont.Meta.tvalues. Defaults tofalse. - If
locsistruelocations are preserved inJsont.Meta.tvalues and error messages are precisely located. Defaults tofalse. fileis the file path from whichris assumed to read. Defaults toJsont.Textloc.file_none
val decode' :
?layout:bool ->
?locs:bool ->
?file:Jsont.Textloc.fpath ->
'a Jsont.t ->
Bytesrw.Bytes.Reader.t ->
('a, Jsont.Error.t) resultdecode' is like decode but preserves the error structure.
val decode_string :
?layout:bool ->
?locs:bool ->
?file:Jsont.Textloc.fpath ->
'a Jsont.t ->
string ->
('a, string) resultdecode_string is like decode but decodes directly from a string.
val decode_string' :
?layout:bool ->
?locs:bool ->
?file:Jsont.Textloc.fpath ->
'a Jsont.t ->
string ->
('a, Jsont.Error.t) resultdecode_string' is like decode' but decodes directly from a string.
Encode
val encode :
?buf:Bytesrw.Bytes.t ->
?format:Jsont.format ->
?number_format:Jsont.number_format ->
'a Jsont.t ->
'a ->
eod:bool ->
Bytesrw.Bytes.Writer.t ->
(unit, string) resultencode t v w encodes value v according to t on w.
- If
bufis specified it is used as a buffer for the slices written onw. Defaults to a buffer of lengthBytes.Writer.slice_lengthw. formatspecifies how the JSON should be formatted. Defaults toJsont.format.Minify.number_formatspecifies the format string to format numbers. Defaults toJsont.default_number_format.eodindicates whetherBytesrw.Bytes.Slice.eodshould be written onw.
val encode' :
?buf:Bytesrw.Bytes.t ->
?format:Jsont.format ->
?number_format:Jsont.number_format ->
'a Jsont.t ->
'a ->
eod:bool ->
Bytesrw.Bytes.Writer.t ->
(unit, Jsont.Error.t) resultencode' is like encode but preserves the error structure.
val encode_string :
?buf:Bytesrw.Bytes.t ->
?format:Jsont.format ->
?number_format:Jsont.number_format ->
'a Jsont.t ->
'a ->
(string, string) resultencode_string is like encode but writes to a string.
val encode_string' :
?buf:Bytesrw.Bytes.t ->
?format:Jsont.format ->
?number_format:Jsont.number_format ->
'a Jsont.t ->
'a ->
(string, Jsont.Error.t) resultencode_string' is like encode' but writes to a string.
Recode
The defaults in these functions are those of decode and encode, except if layout is true, format defaults to Jsont.Layout and vice-versa.
val recode :
?layout:bool ->
?locs:bool ->
?file:Jsont.Textloc.fpath ->
?buf:Bytesrw.Bytes.t ->
?format:Jsont.format ->
?number_format:Jsont.number_format ->
'a Jsont.t ->
Bytesrw.Bytes.Reader.t ->
Bytesrw.Bytes.Writer.t ->
eod:bool ->
(unit, string) resultval recode' :
?layout:bool ->
?locs:bool ->
?file:Jsont.Textloc.fpath ->
?buf:Bytesrw.Bytes.t ->
?format:Jsont.format ->
?number_format:Jsont.number_format ->
'a Jsont.t ->
Bytesrw.Bytes.Reader.t ->
Bytesrw.Bytes.Writer.t ->
eod:bool ->
(unit, Jsont.Error.t) resultrecode' is like recode but preserves the error structure.
val recode_string :
?layout:bool ->
?locs:bool ->
?file:Jsont.Textloc.fpath ->
?buf:Bytesrw.Bytes.t ->
?format:Jsont.format ->
?number_format:Jsont.number_format ->
'a Jsont.t ->
string ->
(string, string) resultrecode is decode_string followed by recode_string.
val recode_string' :
?layout:bool ->
?locs:bool ->
?file:Jsont.Textloc.fpath ->
?buf:Bytesrw.Bytes.t ->
?format:Jsont.format ->
?number_format:Jsont.number_format ->
'a Jsont.t ->
string ->
(string, Jsont.Error.t) resultrecode_string' is like recode_string but preserves the error structure.
Layout preservation
In order to simplify the implementation not all layout is preserved. In particular:
- White space in empty arrays and objects is dropped.
- Unicode escapes are replaced by their UTF-8 encoding.
- The format of numbers is not preserved.
Duplicate object members
Duplicate object members are undefined behaviour in JSON. We follow the behaviour of JSON.parse and the last one takes over, however duplicate members all have to parse with the specified type as we error as soon as possible. Also case members are not allowed to duplicate.