Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

30 lines (22 sloc) 0.766 kB
{-# LANGUAGE TemplateHaskell, OverloadedStrings #-}
import Data.Aeson (decode, encode)
import Data.Aeson.TH (deriveJSON)
import qualified Data.ByteString.Lazy.Char8 as BL
data Color = Red
| White
| Black
deriving (Show)
$(deriveJSON id ''Color)
data Mix = Nullary
| Unary Int
| Normal String String
deriving (Show)
$(deriveJSON id ''Mix)
main :: IO ()
main = do
print ( decode "[\"Red\", \"Black\", \"White\"]" :: Maybe [Color] )
BL.putStrLn (encode [Red, Black, White])
print ( decode "[\"Nullary\"]" :: Maybe [Mix] )
print ( decode "{\"Unary\": 1}" :: Maybe Mix )
print ( decode "{\"Normal\": [\"hello\", \"world\"]}" :: Maybe Mix )
BL.putStrLn (encode [Nullary, Unary 1, Normal "hello" "world"])
Jump to Line
Something went wrong with that request. Please try again.