#OCaml Node JSONFile
WARNING: This binding is partial.
ocaml-node-jsonfile is a binding to the node module jsonfile. It will let you use its functions directly in ocaml
You need to switch to OCaml >= 4.03.0 (due to gen_js_api):
opam switch 4.03.0
First, you need to install ocaml-node if you haven't already installed it
To install this package use the command:
opam pin add ocaml-node-jsonfile https://github.com/besport/ocaml-node-jsonfile.git
Here is an example:
Javascript code:
var jsonfile = require("jsonfile");
var obj = {name: "OCaml"};
jsonfile.writeFileSync("file.json", obj);
Equivalent in OCaml using gen_js_api (for Ojs.t type):
let jsonfile = Node.require "jsonfile" in
let obj = Ojs.empty () in
let () = Ojs.set obj "name" (Ojs.string_to_js "OCaml") in
Node_jsonfile.write_file_sync jsonfile "file.json" obj
You can find the full documentation of jsonfile
on the github repo:
https://github.com/jprichardson/node-jsonfile