Awesome
#OCaml Node JSONFile
WARNING: This binding is partial.
What is ocaml-node-jsonfile?
ocaml-node-jsonfile is a binding to the node module jsonfile. It will let you use its functions directly in ocaml
How to install?
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
How to use?
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
What about the full documentation?
You can find the full documentation of jsonfile
on the github repo:
https://github.com/jprichardson/node-jsonfile