Monday, May 12, 2014

haskell json example

{-# LANGUAGE DeriveDataTypeable #-}
import System.IO
import Text.JSON.Generic


data Person = Person {name :: String} deriving (Show, Data, Typeable)

main = do
  let alex = Person {name = "Alex"}
  putStrLn . encodeJSON $ alex
  let alexJson = encodeJSON $ alex
  putStrLn . show $ (decodeJSON alexJson :: Person)

No comments: