Skip to content

Instantly share code, notes, and snippets.

@ElliotJH
Created April 11, 2013 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ElliotJH/5366546 to your computer and use it in GitHub Desktop.
Save ElliotJH/5366546 to your computer and use it in GitHub Desktop.
{-# 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