Skip to content

JSON contracts for modern OCaml.

Strict, light and derived from your types. Built for JSON Schema, Zod and Melange.

Terminal window
opam repo add hypha https://github.com/hyphatech/opam-repository.git
opam install wiretype ppx_wiretype
line.ml
type line = {
sku : string;
quantity : int; [@min 1] [@max 99] (** how many *)
note : string option; [@max_length 200]
}
[@@deriving wiretype]
(** A line of an order. *)
quick_start.ml
module J = Wiretype
let () =
match
J.decode Line.line_json {|{"sku": "A1", "quantity": 120, "note": 7}|}
with
| Ok _ -> ()
| Error problems ->
List.iter (fun p -> print_endline (J.Problem.to_string p)) problems

Derived from your types

Your records, variants and recursive types are the contract, their bounds and docs included.

Every problem at once

Invalid input is refused with every mistake, each at its path with a code a client can act on.

JSON Schema, Zod and Melange

One walk prints all three, and the Zod and the Melange module are held to the server’s verdict on every test run, so a form finds what is wrong before it sends.