I'm trying to get a simple Json parser up and running in my Haskell code, I came across Data.Aeson which seemed like a viable solution to my problem
I followed the example code on the page, and with some minor modifications, here's what I got:
{-#LANGUAGE OverloadedStrings #-}
import Data.Aeson
import Data.Text
import Control.Applicative
import Control.Monad
data Person =
Person { firstName :: Text
, lastName :: Text
, age :: Int
} deriving Show
instance FromJSON Person where
parseJSON (Object v) =
Person <$> v .: "f_name"
<*> v .: "l_name"
<*> v .: "age"
parseJSON _ = mzero
Running the following in GHCi causes the nasty message in the title to appear:
decode "{\"f_name\":\"Haskell\", \"l_name\":\"Curry\",\"age\":114}" :: Maybe Person
So, does anyone here have an idea what went wrong? I followed the example code almost exactly as it was written, so why is it that it fails?