Module Jsont_codec

JSON codec.

RFC 8259.

Decode

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

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

  • If layout is true whitespace is preserved in Jsonit.Json.Meta.t values. Defaults to false.
  • If locs is true locations are preserved in Jsonit.Json.Meta.t values. Defaults to false.
  • file is the file path from which r is assumed to read (defaults to Jsont.Textloc.file_none) used in the text locations if locs is true.
val decode' : ?layout:bool -> ?locs:bool -> ?file:Jsont.Textloc.fpath -> 'a Jsont.t -> Bytesrw.Bytes.Reader.t -> ('a, Jsont.Error.t) Stdlib.result

decode' 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) Stdlib.result

decode_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) Stdlib.result

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

Encode

val encode : ?buf:Stdlib.Bytes.t -> ?format:Jsont.Json.format -> ?float_precision:int -> 'a Jsont.t -> 'a -> eod:bool -> Bytesrw.Bytes.Writer.t -> (unit, string) Stdlib.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 Bytes.Slice.io_buffer_size. Its size must be at least 4 or Invalid_argument is raised.
  • format specifies how the JSON should be formatted, defaults to Jsont.Json.format.Minify.
  • float_precision specifies the floating point precision. Defaults to 16. Used with the "%.*g" format string.
  • eod indicates whether Bytesrw.Bytes.Slice.eod should be written on w.
val encode' : ?buf:Stdlib.Bytes.t -> ?format:Jsont.Json.format -> ?float_precision:int -> 'a Jsont.t -> 'a -> eod:bool -> Bytesrw.Bytes.Writer.t -> (unit, Jsont.Error.t) Stdlib.result

encode' is like value_to_json but preserves the error structure.

val encode_string : ?buf:Stdlib.Bytes.t -> ?format:Jsont.Json.format -> ?float_precision:int -> 'a Jsont.t -> 'a -> (string, string) Stdlib.result

value_to_json_string is like value_to_json but writes to a string.

val encode_string' : ?buf:Stdlib.Bytes.t -> ?format:Jsont.Json.format -> ?float_precision:int -> 'a Jsont.t -> 'a -> (string, Jsont.Error.t) Stdlib.result

json_string_of_value' is like json_of_value' but writes to a string.

Recode

Layout preservation

In order to simplify the implementation not all layout is preserved. In particular: