Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Parsing JSON in Haskell
{-# LANGUAGE OverloadedStrings, DeriveGeneric #-}
import Data.Text (Text)
import Data.Aeson
import GHC.Generics
import qualified Data.ByteString.Lazy as B
data Person =
Person { first :: !Text
, last :: !Text
, age :: Int
} deriving (Show, Generic)
instance FromJSON Person
instance ToJSON Person
main :: IO ()
main = do
d <-(eitherDecode <$> B.readFile "people.json") :: IO (Either String [Person])
case d of
Left err -> putStrLn err
Right ps -> print $ map (\x -> first x) ps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.