Created
April 11, 2013 19:39
-
-
Save ElliotJH/5366546 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
import Data.Aeson | |
import Data.Maybe | |
import Data.ByteString.Lazy | |
import Control.Applicative | |
main = do | |
res <- liftA show (liftA decodeOriginal (Data.ByteString.Lazy.readFile "./a.json")) | |
Prelude.putStrLn res | |
interpretResult :: Maybe String -> String | |
interpretResult Nothing = "Error." | |
interpretResult x = fromJust x | |
data TotalLine1 = TotalLine1 { | |
timestamp :: Integer, | |
value :: Integer | |
} deriving (Eq, Show) | |
data Original = Original { | |
totals :: [TotalLine1] | |
} deriving (Eq, Show) | |
instance FromJSON Original where | |
parseJSON (Object o) = Original <$> | |
(parseJSON =<< (o .: "visitors.total")) | |
instance FromJSON TotalLine1 where | |
parseJSON (Object o) = TotalLine1 <$> | |
o .: "timestamp" <*> | |
o .: "value" | |
decodeOriginal :: ByteString -> Maybe Original | |
decodeOriginal response = decode response | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment