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

Full commit

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 = Foo | 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 optional: it needs not to exist in Json fields at Json=>OCaml translation.

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

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

} with json

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