Repodb.Embedded.JSON
repodb · API reference
Embedded JSON documents with typed encode/decode schemas.
Embedded.Make(Json) adapts Repodb to any JSON library that satisfies the small JSON signature. The resulting module can decode an embedded JSON object into typed OCaml data, encode it back, and validate embedded payloads inside a Changeset.
Example with an application JSON module:
module Embedded = Repodb.Embedded.Make (App_json)
type profile = { display_name : string; age : int option }
let profile_schema =
Embedded.schema ~name:"profile"
~fields:[ "display_name"; "age" ]
~decode:decode_profile_json
~encode:encode_profile_json
()Use embeds_one_from_json for nullable embedded objects and embeds_many_from_json for JSON arrays. cast_embedded reads a JSON string parameter, decodes it with the schema, and stores the original JSON string in a changeset field. validate_embedded checks that an embedded field can be decoded and adds a validation error when it cannot.
Embedded values are stored as JSON text at the changeset boundary. Persist them in a Types.json field and use Json or Expr's JSON helpers when querying inside the document.
type tval null : tval to_string : t -> stringval of_string : string -> (t, string) resultval get_field : t -> string -> t optionval get_string : t -> string optionval get_int : t -> int optionval get_float : t -> float optionval get_bool : t -> bool optionval get_list : t -> t list optionval is_null : t -> boolval make_object : (string * t) list -> tval make_string : string -> tval make_int : int -> tval make_float : float -> tval make_bool : bool -> tval make_list : t list -> t