Module Jsont.Repr

Low level representation (unstable).

This representation may change even between minor versions of the library. It can be used to devise new processors on JSON types.

Processors should be ready to catch the Json.Error exception when they invoke functional members of the representation.

Processors should also make sure they interpret mappings correctly. In particular:

See the source of Json.decode' and Jsont.encode' for a simple example on how to process this representation.

type 'a t' := 'a t
module String_map : Stdlib.Map.S with type key = string
module Type : sig ... end

Type identifiers. Can be removed once we require OCaml 5.1

type ('ret, 'f) dec_fun =
  1. | Dec_fun : 'f -> ('ret, 'f) dec_fun
  2. | Dec_app : ('ret, 'a -> 'b) dec_fun * 'a Type.Id.t -> ('ret, 'b) dec_fun
type ('a, 'b) base_map = {
  1. kind : string;
  2. doc : string;
  3. dec : Context.t -> Meta.t -> 'a -> 'b;
  4. enc : Context.t -> 'b -> 'a;
  5. enc_meta : Context.t -> 'b -> Meta.t;
}
type 'a t =
  1. | Null : (unit, 'a) base_map -> 'a t
  2. | Bool : (bool, 'a) base_map -> 'a t
  3. | Number : (float, 'a) base_map -> 'a t
  4. | String : (string, 'a) base_map -> 'a t
  5. | Array : ('a, 'elt, 'builder) array_map -> 'a t
  6. | Obj : ('o, 'o) obj_map -> 'o t
  7. | Any : 'a any_map -> 'a t
  8. | Map : ('a, 'b) map -> 'b t
  9. | Rec : 'a t Stdlib.Lazy.t -> 'a t
and ('array, 'elt, 'builder) array_map = {
  1. kind : string;
  2. doc : string;
  3. elt : 'elt t;
  4. dec_empty : Context.t -> 'builder;
  5. dec_skip : Context.t -> int -> 'builder -> bool;
  6. dec_add : Context.t -> int -> 'elt -> 'builder -> 'builder;
  7. dec_finish : Context.t -> Meta.t -> int -> 'builder -> 'array;
  8. enc : 'acc. Context.t -> ('acc -> int -> 'elt -> 'acc) -> 'acc -> 'array -> 'acc;
  9. enc_meta : Context.t -> 'array -> Meta.t;
}
and ('o, 'dec) obj_map = {
  1. kind : string;
  2. doc : string;
  3. dec : ('o, 'dec) dec_fun;
  4. mem_decs : mem_dec String_map.t;
  5. mem_encs : 'o mem_enc list;
  6. enc_meta : Context.t -> 'o -> Meta.t;
  7. shape : 'o obj_shape;
}
and mem_dec =
  1. | Mem_dec : ('o, 'a) mem_map -> mem_dec
and 'o mem_enc =
  1. | Mem_enc : ('o, 'a) mem_map -> 'o mem_enc
and ('o, 'a) mem_map = {
  1. name : string;
  2. doc : string;
  3. type' : 'a t;
  4. id : 'a Type.Id.t;
  5. dec_absent : 'a option;
  6. enc : Context.t -> 'o -> 'a;
  7. enc_meta : Context.t -> 'a -> Meta.t;
  8. enc_omit : Context.t -> 'a -> bool;
}
and 'o obj_shape =
  1. | Obj_basic : ('o, 'mems, 'builder) unknown_mems -> 'o obj_shape
  2. | Obj_cases : ('o, 'cases, 'tag) obj_cases -> 'o obj_shape
and ('o, 'mems, 'builder) unknown_mems =
  1. | Unknown_skip : ('o, unit, unit) unknown_mems
  2. | Unknown_error : ('o, unit, unit) unknown_mems
  3. | Unknown_keep : ('mems, 'a, 'builder) mems_map * ('o -> 'mems) -> ('o, 'mems, 'builder) unknown_mems
and ('mems, 'a, 'builder) mems_map = {
  1. kind : string;
  2. doc : string;
  3. mems_type : 'a t;
  4. id : 'mems Type.Id.t;
  5. dec_empty : Context.t -> 'builder;
  6. dec_add : Context.t -> Meta.t -> string -> 'a -> 'builder -> 'builder;
  7. dec_finish : Context.t -> 'builder -> 'mems;
  8. enc : 'acc. Context.t -> (Meta.t -> string -> 'a -> 'acc -> 'acc) -> 'mems -> 'acc -> 'acc;
}
and ('o, 'cases, 'tag) obj_cases = {
  1. tag : ('tag, 'tag) mem_map;
  2. tag_compare : 'tag -> 'tag -> int;
  3. id : 'cases Type.Id.t;
  4. cases : ('cases, 'tag) case list;
  5. enc : 'o -> 'cases;
  6. enc_case : Context.t -> 'cases -> ('cases, 'tag) case_value;
}
and ('cases, 'case, 'tag) case_map = {
  1. tag : 'tag;
  2. obj_map : ('case, 'case) obj_map;
  3. dec : 'case -> 'cases;
}
and ('cases, 'tag) case_value =
  1. | Case_value : ('cases, 'case, 'tag) case_map * 'case -> ('cases, 'tag) case_value
and ('cases, 'tag) case =
  1. | Case : ('cases, 'case, 'tag) case_map -> ('cases, 'tag) case
and 'a any_map = {
  1. kind : string;
  2. doc : string;
  3. dec_null : 'a t option;
  4. dec_bool : 'a t option;
  5. dec_number : 'a t option;
  6. dec_string : 'a t option;
  7. dec_array : 'a t option;
  8. dec_obj : 'a t option;
  9. enc : Context.t -> 'a -> 'a t;
}
and ('a, 'b) map = {
  1. kind : string;
  2. doc : string;
  3. dom : 'a t;
  4. dec : Context.t -> 'a -> 'b;
  5. enc : Context.t -> 'b -> 'a;
}

Convert

val of_t : 'a t' -> 'a t

of_t is Stdlib.Fun.id.

val type_error : Context.t -> Meta.t -> 'a t -> fnd:Sort.t -> 'b

type_error ctx m t is like Error.kind but exp is derived from t.

val kind : 'a t -> string

kind m is the kind of definition of m.

val obj_map_kind : ('o, 'dec) obj_map -> string

obj_map_kind m is the kind of definition of m.

Toolbox

val pp_code : string fmt
module Dict : sig ... end

Heterogeneous dictionaries.

val apply_dict : ('ret, 'f) dec_fun -> Dict.t -> 'f
val obj_context_arg : Context.t Type.Id.t
val obj_meta_arg : Meta.t Type.Id.t