[Haskell-cafe] JSON serialization/deserialization

Marc Weber marco-oweber at gmx.de
Fri Sep 12 12:34:36 EDT 2008

The trouble:
module A
data ABC = A { a :: String }
         | B { a :: String }
         | C { a :: String }

module B
data ABC = A { a :: String }
         | B { a :: String }
         | C { a :: String }

is valid haskell.
so how should you know having the serialized String { a : "abc" }
wether to use the constructor A,B,C ? or wether to use ABC from module A
or from B?
There are many ways to solve this:
One is to serialize it this way: { "datatype": "A.ABC", constructor : "C"
                                 , a :"text" }
or such..
Maybe also read about Data.Typable, have a look at derive or DrIft (or
the lib itself, I'm not sure wethere there is one which has choosen one
way to do this)..

Basically JavaScript doesn't have real typing (such as classes). But
there exist some libraries to emulate it such as mootools or

I hope you'll find a solution which works for you.

Marc Weber

More information about the Haskell-Cafe mailing list