From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id CE84ABB84 for ; Sun, 1 Jun 2008 13:17:20 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsQAAJMhQkjAXQInlmdsb2JhbACSCwEBAQEJBQgYmUM X-IronPort-AV: E=Sophos;i="4.27,573,1204498800"; d="scan'208";a="13331456" Received: from concorde.inria.fr ([192.93.2.39]) by mail3-smtp-sop.national.inria.fr with ESMTP; 01 Jun 2008 13:17:20 +0200 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m51BHJmc009143 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Sun, 1 Jun 2008 13:17:20 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmQAAGAiQkhCbwQZlGdsb2JhbACSCwEBAQEJAwoHEQSZNg X-IronPort-AV: E=Sophos;i="4.27,573,1204498800"; d="scan'208";a="13043722" Received: from out1.smtp.messagingengine.com ([66.111.4.25]) by mail1-smtp-roc.national.inria.fr with ESMTP; 01 Jun 2008 13:17:19 +0200 Received: from compute1.internal (compute1.internal [10.202.2.41]) by out1.messagingengine.com (Postfix) with ESMTP id A01A8110BE7; Sun, 1 Jun 2008 07:17:18 -0400 (EDT) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by compute1.internal (MEProxy); Sun, 01 Jun 2008 07:17:18 -0400 X-Sasl-enc: EAgzc0ygLwoMR6oYe4kiNG1LP3A+J0so8SsNoALUQjIa 1212319038 Received: from [192.168.1.10] (ALyon-157-1-145-205.w90-42.abo.wanadoo.fr [90.42.152.205]) by mail.messagingengine.com (Postfix) with ESMTPSA id A92BEF3DE; Sun, 1 Jun 2008 07:17:17 -0400 (EDT) Date: Sun, 1 Jun 2008 13:14:29 +0200 (CEST) From: Martin Jambon X-X-Sender: martin@martin.ec.wink.com To: Berke Durak Cc: Robert Fischer , caml-list@inria.fr Subject: Re: [Caml-list] picking / marshaling to strings in ocaml-revision-stable way In-Reply-To: Message-ID: References: <28fa90930805302343n18b98b17t72a22ea82539fc6f@mail.gmail.com> <20080531.174314.107716495.garrigue@math.nagoya-u.ac.jp> <28fa90930805310954w3089478bqfd8c3f821fff207e@mail.gmail.com> <48418421.5090601@fischerventure.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at concorde with ID 4842853F.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ens-lyon:01 marshaling:01 berke:01 durak:01 syntax:01 sexp:01 fprintf:01 fprintf:01 iter:01 arrays:01 booleans:01 bool:01 bool:01 cheers:01 atoms:98 On Sat, 31 May 2008, Berke Durak wrote: > 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 > 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 objects. 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 Cheers, Martin -- http://wink.com/profile/mjambon http://mjambon.com