Autogeneration of JSON exporter from OCaml datatypes in multiple code bases

Hello, Ocaml beginner here.

I want to know how best to auto-derive code that exports values in an OCaml data type with a huge chain of dependencies on two code bases (in different GitHub repos) that I cannot change (annotate with [@@deriving yojson]), including the Ocaml standard library, in particular for arbitrary precision arithmetic (Zarith).

What I have done is manually to duplicate all relevant data type definitions, and annotated them with [@@deriving yojson]. That works (except for a fudge regarding arbitrary precision arithmetic), but does not help when the underlying repos change. What I’d like is to automate the whole process, so I simply specify the base-type to be serialised to JSON (and links to the GitHub repo dependencies) and everything else works automatically. I can see how to do the relevant scripting myself, but it looks like a huge amount of effort. Surely this problem must have been encountered by others before.

What’s the recommended approach in 2021?