English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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-06-01 (11:17)
From: Martin Jambon <martin.jambon@e...>
Subject: Re: [Caml-list] picking / marshaling to strings in ocaml-revision-stable way
On Sat, 31 May 2008, Berke Durak wrote:

> On Sat, May 31, 2008 at 7:00 PM, Robert Fischer
> <robert@fischerventure.com> 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
> Sexp.t
>  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.

You won't obtain anything useful if you treat Atoms as JSON strings and 
Lists as JSON arrays because JSON has also null, numbers, booleans and 

This is the JSON standard: http://www.json.org/

And that is the concrete type used to represent JSON trees in the 
json-wheel library (which json-static uses):

type json_type =
     Object of (string * json_type) list
   | Array of json_type list
   | String of string
   | Int of int
   | Float of float
   | Bool of bool
   | Null