Created
December 10, 2011 14:22
-
-
Save onlyshk/1455279 to your computer and use it in GitHub Desktop.
Json encoding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
module Test where | |
import Data.Aeson | |
import Data.ByteString.Lazy.Char8 as B | |
data Auto = Auto {firm :: String, year :: Int, price :: Int, sellers :: [String]} | |
deriving (Show) | |
instance ToJSON Auto where | |
toJSON (Auto firm year price sellers) = object [ "firm" .= firm, | |
"year" .= year, | |
"price" .= price, | |
"sellers" .= sellers | |
] | |
main = do | |
let test = encode $ Auto "Audi" 2000 100000 ["Firm1", "Firm2"] | |
B.putStrLn test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment