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 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id C94CBBBCA for ; Fri, 21 Mar 2008 00:01:46 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArgAAAOK4kdCbwQak2dsb2JhbACRBQEBAQEJAwkJFpoD X-IronPort-AV: E=Sophos;i="4.25,533,1199660400"; d="scan'208";a="9756497" Received: from out2.smtp.messagingengine.com ([66.111.4.26]) by mail1-smtp-roc.national.inria.fr with ESMTP; 21 Mar 2008 00:01:46 +0100 Received: from compute2.internal (compute2.internal [10.202.2.42]) by out1.messagingengine.com (Postfix) with ESMTP id D7EDED8F2E; Thu, 20 Mar 2008 19:01:44 -0400 (EDT) Received: from heartbeat2.messagingengine.com ([10.202.2.161]) by compute2.internal (MEProxy); Thu, 20 Mar 2008 19:01:44 -0400 X-Sasl-enc: s8ZJL2GxcrzqYRVD8hsHROlYt1wEy325F8Pq0myr4siu 1206054104 Received: from [192.168.1.10] (ALyon-157-1-20-67.w81-251.abo.wanadoo.fr [81.251.179.67]) by mail.messagingengine.com (Postfix) with ESMTPSA id 1F22F18BBC; Thu, 20 Mar 2008 19:01:43 -0400 (EDT) Date: Fri, 21 Mar 2008 00:00:46 +0100 (CET) From: Martin Jambon X-X-Sender: martin@martin.ec.wink.com To: Dario Teixeira Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Long-term storage of values In-Reply-To: <736358.98739.qm@web54607.mail.re2.yahoo.com> Message-ID: References: <736358.98739.qm@web54607.mail.re2.yahoo.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Spam: no; 0.00; ens-lyon:01 marshalling:01 ocaml:01 ocaml:01 val:01 val:01 syntax:01 serialize:01 wrote:01 caml-list:01 functions:01 functions:01 int:01 int:01 jambon:01 On Thu, 20 Mar 2008, Dario Teixeira wrote: >> >> There's json-static for automatic marshalling: >> >> http://martin.jambon.free.fr/json-static.html > > Hi, > > Thanks for your reply, Martin. Looking at the examples, it seems that > json-static is JSON-centric, in the sense that the type definitions for > the automatic (de)serialisers are to be written in JSON. Does it support > the reverse, namely "here's an Ocaml type: please write Ocaml functions > that (de)serialise into JSON"? Dario, No JSON needs to be written by hand. Here's a simple example: type json point = { x : int; y : int } (* an OCaml record *) It creates the functions with the following signature: val json_of_point : point -> Json_type.t val point_of_json : Json_type.t -> point Json_type.t is the JSON syntax tree that you can serialize using Json_io.string_of_json. # let j = json_of_point { x = 12; y = 34 };; val j : Json_type.t = Json_type.Object [("x", Json_type.Int 12); ("y", Json_type.Int 34)] # Json_io.string_of_json j;; - : string = "{ \"x\": 12, \"y\": 34 }" Martin -- http://wink.com/profile/mjambon http://martin.jambon.free.fr