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.to_value' and Jsont.of_value' 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 ('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, 'b) array_map -> 'a t
  6. | Obj : '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 -> Meta.t -> 'array;
  5. dec_first : Context.t -> 'elt -> 'builder;
  6. dec_next : Context.t -> int -> 'elt -> 'builder -> 'builder;
  7. dec_finish : Context.t -> Meta.t -> 'builder -> 'array;
  8. enc : 'acc. Context.t -> ('acc -> int -> 'elt -> 'acc) -> 'acc -> 'array -> 'acc;
  9. enc_meta : Context.t -> 'array -> Meta.t;
}
and 'o obj_map = {
  1. mems : ('o, 'o) obj_mems;
  2. mems_by_name : 'o e_mem_map String_map.t;
}
and ('o, 'dec) obj_mems =
  1. | Obj_def : ('o, 'dec, _) obj_def -> ('o, 'dec) obj_mems
  2. | Obj_mem : ('o, 'a -> 'b) obj_mems * ('o, 'a, _) mem_map -> ('o, 'b) obj_mems
and ('o, 'dec, 'unknown) obj_def = {
  1. kind : string;
  2. doc : string;
  3. dec : Context.t -> Meta.t -> 'unknown -> 'dec;
  4. enc_meta : Context.t -> 'o -> Meta.t;
  5. unknown : ('o, 'unknown) unknown;
}
and ('o, 'mems) unknown =
  1. | Unknown_error : ('o, unit) unknown
  2. | Unknown_drop : ('o, unit) unknown
  3. | Unknown_map : ('mems, 'a) unknown_map * ('o -> 'mems) -> ('o, 'mems) unknown
and ('mems, 'a) unknown_map = {
  1. kind : string;
  2. doc : string;
  3. type' : 'a t;
  4. id : 'mems Jsont_base.Type.Id.t;
  5. dec_empty : Context.t -> 'mems;
  6. dec_add : Meta.t -> string -> 'a -> 'mems -> 'mems;
  7. enc : 'acc. (Meta.t -> string -> 'a -> 'acc -> 'acc) -> 'mems -> 'acc -> 'acc;
}
and ('o, 'mem, 'a) mem_map = {
  1. name : string;
  2. doc : string;
  3. type' : ('mem, 'a) mem_type;
  4. id : 'mem Type.Id.t;
  5. dec_absent : 'a option;
  6. dec : Context.t -> Meta.t -> string -> 'a -> 'mem;
  7. enc : Context.t -> 'o -> 'mem;
  8. enc_meta : Context.t -> 'a -> Meta.t;
  9. enc_omit : Context.t -> 'a -> bool;
}
and 'o e_mem_map =
  1. | Mem_map : ('o, 'mem, 'a) mem_map -> 'o e_mem_map
and ('mem, 'a) mem_type =
  1. | Mem : 'a t -> ('a, 'a) mem_type
  2. | Case_mem : ('cases, 'tag) obj_cases -> ('cases, ('cases, 'tag) case_value) mem_type
and ('cases, 'tag) obj_cases = {
  1. tag : 'tag t;
  2. cases : ('cases, 'tag) case_part list;
  3. enc : Context.t -> 'cases -> ('cases, 'tag) case_value;
}
and ('cases, 'case, 'tag) case = {
  1. tag : 'tag;
  2. obj : 'case obj_map;
  3. dec : 'case -> 'cases;
}
and ('cases, 'tag) case_value =
  1. | Case_value : ('cases, 'case, 'tag) case * 'case -> ('cases, 'tag) case_value
and ('cases, 'tag) case_part =
  1. | Case : ('cases, 'case, 'tag) case -> ('cases, 'tag) case_part
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 obj_kind : ('o, 'ctor) obj_mems -> string

obj_kind mems is the kind of the definition of mems.

val kind : 'a t -> string
val pp_code : string fmt