Module Jsont_typegist

Derive JSON types from OCaml type gists.

The to_jsont function derives a Jsont.t value from a Typegist.Type.Gist.t value.

A few metadata keys in Meta keys can be used to customize the computed JSON type or selectively override the deriving function with a manually provided Jsont.t value.

See an example.

module Meta : sig ... end

Metadata for customizing to_jsont.

val to_jsont : 'a Typegist.Type.Gist.t -> 'a Jsont.t

to_jsont g is a JSON type derived fom g.

In general:

  • Typegist.Type.Gist.type_name is used for Jsont.kind.
  • Typegist.Type.Gist.Meta.Doc (if any) is used for Jsont.doc.

Note the following:

  • Typegist.Type.Gist.Float uses Jsont.number by default.
  • Typegist.Type.Gist.Int64 uses Jsont.int64 by default.
  • Typegist.Type.Gist.String uses Jsont.string by default.
  • Typegist.Type.Gist.String uses a transformed Jsont.binary_string by default.

Raises Invalid_argument in the following cases:

val gist : 'a Typegist.Type.Gist.t -> 'a Jsont.t Typegist.Type.Gist.t

gist g is a gist for JSON type values. This is not really usable in general but can be useful to inspect Jsont.t values with Typegist.Fun.Generic.pp.

Example

This example overrides the string key.