Parsing JSON in OCaml

Hi,

So I just figured out how to set up VSCode on WSL2/Ubuntu and ran a basic code that reads a json file and prints the length of the string.

I now want to be able to work with data from the file and for this I created a types.adt file with the type definition of the objects in the JSON file.
I ran adtgen on it and got the types.adt_j.ml and types.adt_j.mli

I see that types.adt_j.ml has a function that takes a string and returns my custom type.
But how do I call this function?

Folder Structure:
app.ml
types/
types.adt
types.adt_j.ml
types.adt_j.mli

In app.ml how do I call the function in types.adt_j.ml?

The extension should be .atd, not .adt. Then, atdgen will recognize it and remove it. You’ll get types_j.mli and types_j.ml (from types.atd).

You can then inspect the mli file to see what’s provided. The module name, as usual in ocaml, is the capitalized version of the file name without extension, in this case Types_j. So you’d call Types_j.yourtype_of_string "{...}" to read a json blob.