[Haskell-beginners] Parse Json tweets using Aeson

Tushar Jarhad tjarhad at gmail.com
Thu Sep 18 22:23:50 UTC 2014


{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}

import Data.Aeson
import GHC.Generics
import qualified Data.ByteString.Lazy as B

data  Tweet  =  Tweet {
                        id_str :: String,
                        text   :: String
                      }deriving Generic


instance FromJSON Tweet


main = do
  input <- B.readFile "1.json"
  let mm = decode input :: Maybe Tweet
  case mm of
    Nothing -> print "error parsing JSON"
    Just m -> (putStrLn.greet) m

greet m = (show.id_str) m


This program is fine if 1.json file has 1 tweet
if 1.json file has multiple tweets then it fails
so how we can parse multiple tweets
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140919/fd82005d/attachment.html>


More information about the Beginners mailing list