-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parser.hs
36 lines (31 loc) · 1.13 KB
/
Parser.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{-# LANGUAGE RecordWildCards, OverloadedStrings #-}
module Parser ( encode
, decode
, Transaction(..)
, TId
, FromJSON(..)
, ToJSON(..)
) where
import Data.Aeson
import Data.Monoid
import Control.Applicative
type TId = String
data Transaction = Transaction { from :: String
, to :: String
, amount :: Integer
, tid :: TId
}
deriving (Show, Eq)
instance FromJSON Transaction where
parseJSON (Object v) = Transaction <$>
v .: "from" <*>
v .: "to" <*>
v .: "amount" <*>
v .: "tid"
parseJSON _ = mempty
instance ToJSON Transaction where
toJSON Transaction{..} = object [ "from" .= from
, "to" .= to
, "amount" .= amount
, "tid" .= tid
]