Module Tpf_json.Enc

Generic JSON encoder.

Records are represented as JSON objects, and constant constructors are represented as JSON strings.

The representation of variants is determined by the ~sum argument (default arr).

Generic function

include Tpf.P with type 'a q := 'a e
type 'a q

Query type.

type p

q proxy.

val (!) : 'a q -> ('ap) Tpf.app

Injection.

type sum = string -> json list -> json

Sum-formatting functions. f name args is the JSON encoding of constructor named name, with arguments args.

val arr : sum

Formats K (a0, a1, ...) as ["K", a0, a1, ...].

val obj : ?⁠tag:string -> ?⁠values:string -> sum

Formats K (a0, a1, ...) as { tag: "K", values: [a0, a1, ...]}.

tag defaults to "tag" and values defaults to "values".

val g_to_json : ?⁠sum:sum -> ('ap) Tpf.view -> 'a e

data interface

val data0 : ?⁠sum:sum -> 'x Tpf.data0 -> 'x e
val data1 : ?⁠sum:sum -> ('a'x) Tpf.data1 -> 'a e -> 'x e
val data2 : ?⁠sum:sum -> ('a'b'x) Tpf.data2 -> 'a e -> 'b e -> 'x e
val data3 : ?⁠sum:sum -> ('a'b'c'x) Tpf.data3 -> 'a e -> 'b e -> 'c e -> 'x e
val data4 : ?⁠sum:sum -> ('a'b'c'd'x) Tpf.data4 -> 'a e -> 'b e -> 'c e -> 'd e -> 'x e
val data5 : ?⁠sum:sum -> ('a'b'c'd'e'x) Tpf.data5 -> 'a e -> 'b e -> 'c e -> 'd e -> 'e e -> 'x e
val data6 : ?⁠sum:sum -> ('a'b'c'd'e'f'x) Tpf.data6 -> 'a e -> 'b e -> 'c e -> 'd e -> 'e e -> 'f e -> 'x e
val data7 : ?⁠sum:sum -> ('a'b'c'd'e'f'g'x) Tpf.data7 -> 'a e -> 'b e -> 'c e -> 'd e -> 'e e -> 'f e -> 'g e -> 'x e
val data8 : ?⁠sum:sum -> ('a'b'c'd'e'f'g'h'x) Tpf.data8 -> 'a e -> 'b e -> 'c e -> 'd e -> 'e e -> 'f e -> 'g e -> 'h e -> 'x e
val data9 : ?⁠sum:sum -> ('a'b'c'd'e'f'g'h'i'x) Tpf.data9 -> 'a e -> 'b e -> 'c e -> 'd e -> 'e e -> 'f e -> 'g e -> 'h e -> 'i e -> 'x e