[Haskell-beginners] Help with Data.Aeson json data parsing

Miro Karpis miroslav.karpis at gmail.com
Fri Jan 3 23:42:33 UTC 2014


Hi, please can you help me with following? I'm trying to parse one json
(simplified version below), but I keep getting:

"when expecting a record (:*:), encountered Array instead"


code:
------------

data SomeData = SomeData {
    v1 :: Int,
    v2 :: Int
} deriving (Show, Generic)

data SomeDataPack = SomeDataPack{
    pack :: [SomeData]
} deriving (Show, Generic)

instance FromJSON SomeData
instance FromJSON SomeDataPack

parsedata :: IO (Maybe SomeDataPack)
parsedata = do
    let x = "[{\"v1\":11,\"v2\":12},{\"v1\":13,\"v2\":14}]";
    case (eitherDecode' x :: Either String SomeDataPack) of
           Right r -> do
                putStrLn $ show r
                return $ Just r
           Left e -> do
                putStrLn $ show e
                return Nothing


thanks,
m.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140104/cd5870fa/attachment.html>


More information about the Beginners mailing list