package jsont

  1. Overview
  2. Docs
Declarative JSON data manipulation for OCaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

jsont-0.2.0.tbz
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

Sourceval decode : ?layout:bool -> ?locs:bool -> ?file:Jsont.Textloc.fpath -> 'a Jsont.t -> Bytesrw.Bytes.Reader.t -> ('a, string) result

decode t r decodes a value from r according to t.

  • If layout is true whitespace is preserved in Jsont.Meta.t values. Defaults to false.
  • If locs is true locations are preserved in Jsont.Meta.t values and error messages are precisely located. Defaults to false.
  • file is the file path from which r is assumed to read. Defaults to Jsont.Textloc.file_none
Sourceval decode' : ?layout:bool -> ?locs:bool -> ?file:Jsont.Textloc.fpath -> 'a Jsont.t -> Bytesrw.Bytes.Reader.t -> ('a, Jsont.Error.t) result

decode' is like decode but preserves the error structure.

Sourceval decode_string : ?layout:bool -> ?locs:bool -> ?file:Jsont.Textloc.fpath -> 'a Jsont.t -> string -> ('a, string) result

decode_string is like decode but decodes directly from a string.

Sourceval decode_string' : ?layout:bool -> ?locs:bool -> ?file:Jsont.Textloc.fpath -> 'a Jsont.t -> string -> ('a, Jsont.Error.t) result

decode_string' is like decode' but decodes directly from a string.

Encode

Sourceval 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) result

encode t v w encodes value v according to t on w.

  • If buf is specified it is used as a buffer for the slices written on w. Defaults to a buffer of length Bytes.Writer.slice_length w.
  • format specifies how the JSON should be formatted. Defaults to Jsont.format.Minify.
  • number_format specifies the format string to format numbers. Defaults to Jsont.default_number_format.
  • eod indicates whether Bytesrw.Bytes.Slice.eod should be written on w.
Sourceval 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) result

encode' is like encode but preserves the error structure.

Sourceval encode_string : ?buf:Bytesrw.Bytes.t -> ?format:Jsont.format -> ?number_format:Jsont.number_format -> 'a Jsont.t -> 'a -> (string, string) result

encode_string is like encode but writes to a string.

Sourceval encode_string' : ?buf:Bytesrw.Bytes.t -> ?format:Jsont.format -> ?number_format:Jsont.number_format -> 'a Jsont.t -> 'a -> (string, Jsont.Error.t) result

encode_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.

Sourceval 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) result

recode is decode followed by recode.

Sourceval 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) result

recode' is like recode but preserves the error structure.

Sourceval 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) result

recode is decode_string followed by recode_string.

Sourceval 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) result

recode_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.

OCaml

Innovation. Community. Security.