ocaml-json-tc-custom / README.custom.rst

JSON type-conv custom

caml field and CAML constructor names

To work with Json names which are OCaml registered keywords like "type", uppercase field names, and lowercase tag names, a special handling is introduced for OCaml record fields and constructors which start with "caml_" and "CAML_" respectively:

type t = CAML_text with json (\* in Json, not "CAML_text" but "text" \*)

type r = { caml_type : t } with json (\* in Json, not "caml_type" but "type" \*)

optional type

Data type name "optional" in OCaml record field type is specially handled. It works as the option type, but the field can be really optional. The field need not to exist in Json fields at Json => OCaml translation.

type 'a optional = 'a option (* You need to declare this alias *)

type r = { id : Id.t; (\* mandatory field \*)
source_url : string optional; (* if not exists in Json, None in OCaml *)

} with json

CR jfuruse: No OCaml => Json handling of optional is considered yet.