Parsing JSON in OCaml


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 and types.adt_j.mli

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

Folder Structure:

In how do I call the function in

The extension should be .atd, not .adt. Then, atdgen will recognize it and remove it. You’ll get types_j.mli and (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.