Skip to content

Instantly share code, notes, and snippets.

@onlyshk
Created December 10, 2011 14:22
Show Gist options
  • Save onlyshk/1455279 to your computer and use it in GitHub Desktop.
Save onlyshk/1455279 to your computer and use it in GitHub Desktop.
Json encoding
{-# 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