Module Jsont.Base

JSON base type maps.

Maps

type ('a, 'b) map

The type for maps of values of type 'a to values of type 'b.

val map : ?kind:string -> ?doc:string -> ?dec:(Context.t -> Meta.t -> 'a -> 'b) -> ?enc:(Context.t -> 'b -> 'a) -> ?enc_meta:(Context.t -> 'b -> Meta.t) -> unit -> ('a, 'b) map

map ~kind ~doc ~dec ~enc ~enc_meta () represents values of type 'a by values of type 'b with:

  • kind names the entities represented by type 'b. Defaults to "".
  • doc is a documentation string for kind. Defaults to "".
  • dec is used to decode values of type 'a to values of type 'b. Can be omitted if the result is only used for encoding, the default unconditionally errors.
  • enc is used to encode values of type 'b to values of type 'a. Can be omitted if the result is only used for decoding, the default unconditionally errors.
  • enc_meta is used to recover JSON metadata from a value to encode. The default unconditionnaly returns Json.Meta.none.

See also Base.map_result, Base.map_failure.

val map_result : ?kind:string -> ?doc:string -> ?dec:('a -> ('b, string) Stdlib.result) -> ?enc:('b -> 'a) -> ?enc_meta:(Context.t -> 'b -> Meta.t) -> unit -> ('a, 'b) map

map_result is like map but interfaces with a result based decoding function and assumes enc always succeeds though it turns Failure _ exceptions into Jsont.Json.Error exceptions. See also, map and map_failure.

val map_failure : ?kind:string -> ?doc:string -> ?dec:('a -> 'b) -> ?enc:('b -> 'a) -> ?enc_meta:(Context.t -> 'b -> Meta.t) -> unit -> ('a, 'b) map

map_failure is like map but interfaces with t_{of,to} function pairs that raise Stdlib.Failure.

val id : ('a, 'a) map

id is the identity map.

val ignore : ('a, unit) map

ignore is the ignoring map. It ignores decodes and errors on encodes.

Maps as JSON types

val null : (unit, 'a) map -> 'a t

null map represents JSON nulls initially represented by () by the value of type 'a encoded by map. See also Jsont.null.

val bool : (bool, 'a) map -> 'a t

bool map represents JSON booleans initially represented by bool values by the values of type 'a encoded by map. See also Jsont.bool.

val number : (float, 'a) map -> 'a t

number map represents JSON nulls or numbers initially represented by float values by the values of type 'a encoded by map. The initial float representation decodes JSON nulls to Float.nan and lossily encodes any non-finite to JSON null (explanation). See also Jsont.number.

val string : (string, 'a) map -> 'a t

string m represents JSON strings initially represented by by UTF-8 encoded and unescaped string values by the the values of type 'a encoded by map. See also Jsont.string.