Module Basic_monad.Make

The Make functor is used to create a module with reader and writer functions using the IO monad.

Parameters

Signature

The Make functor is used to create a module with reader and writer functions using the IO monad. This has the signature

module type IO = sig
  type 'a t

  val return : 'a -> 'a t
  val (>>=)  : 'a t -> ('a -> 'b t) -> 'b t
end
include Jsonxt__.Reader_monad.Reader_monad with type json := Basic.Compliance.json and module IO := IO
type json
val read_json : ?⁠stream:bool -> reader:(Stdlib.Bytes.t -> int -> int IO.t) -> unit -> (json, string) Stdlib.result IO.t

read_json takes a reader function and returns a json value or an error if the string has syntax, grammar or compliance errors. The reader buf len parameter reads at most len bytes into buf and returns the number of bytes read. Zero indicates end of file. The optional stream parameter specifies if multiple json objects are to be read, defaulting to false

include Jsonxt__.Writer_monad_intf.Intf with type json := Basic.Compliance.json and module IO := IO
type json
val json_writer : writer:(string -> unit IO.t) -> eol:string -> incr:int -> psep:string -> json -> unit IO.t

json_writer ~writer ~eol ~incr ~psep json converts json to a string s and writes it out using the writer string function. incr, eol and psep work together to output human readable output. incr defines the increase in indentation, eol the end of line sequence and psep the string to seperate the : from the value in objects

The writer string function takes a string and returns a unit IO.t

val write_json : writer:(string -> unit IO.t) -> json -> unit IO.t

create_encoder ~writer creates a compact encoder using json_writer.

val write_json_hum : writer:(string -> unit IO.t) -> json -> unit IO.t

create_encoder ~writer creates a human readable encoder using json_writer with incr set to 2 and eol to '\n'.