Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
picking / marshaling to strings in ocaml-revision-stable way
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-05-31 (21:34)
From: Berke Durak <berke.durak@g...>
Subject: Re: [Caml-list] picking / marshaling to strings in ocaml-revision-stable way
On Sat, May 31, 2008 at 7:00 PM, Robert Fischer
<> wrote:
> How far is the reach from the Jane St S-exp library from producing JSON?  I've not actually looked at it, but that'd be super nifty in the interoperation world.

If you just want JSON syntax, you can use Sexplib to convert an
arbitrary type to a

  type t = Atom of string | List of t list

and then output in Json format:

let rec output_json oc = function
| Atom u -> fprintf oc "%S" u
| List xl -> fprintf oc "[%a]" (fun oc xl -> List.iter (fun x ->
fprintf "%a," output_json x) xl) xl

You can then do the same thing for parsing.