;lib: drop more unnecessary toJSON calls

This commit is contained in:
Simon Michael 2019-12-27 15:49:42 -08:00
parent 7e49d8cce9
commit c5537cedb5

View File

@ -59,20 +59,20 @@ instance ToJSON PostingType
instance ToJSON Posting where instance ToJSON Posting where
toJSON Posting{..} = object toJSON Posting{..} = object
["pdate" .= toJSON pdate ["pdate" .= pdate
,"pdate2" .= toJSON pdate2 ,"pdate2" .= pdate2
,"pstatus" .= toJSON pstatus ,"pstatus" .= pstatus
,"paccount" .= toJSON paccount ,"paccount" .= paccount
,"pamount" .= toJSON pamount ,"pamount" .= pamount
,"pcomment" .= toJSON pcomment ,"pcomment" .= pcomment
,"ptype" .= toJSON ptype ,"ptype" .= ptype
,"ptags" .= toJSON ptags ,"ptags" .= ptags
,"pbalanceassertion" .= toJSON pbalanceassertion ,"pbalanceassertion" .= pbalanceassertion
-- To avoid a cycle, show just the parent transaction's index number -- To avoid a cycle, show just the parent transaction's index number
-- in a dummy field. When re-parsed, there will be no parent. -- in a dummy field. When re-parsed, there will be no parent.
,"ptransaction_" .= toJSON (maybe "" (show.tindex) ptransaction) ,"ptransaction_" .= maybe "" (show.tindex) ptransaction
-- This is probably not wanted in json, we discard it. -- This is probably not wanted in json, we discard it.
,"poriginal" .= toJSON (Nothing :: Maybe Posting) ,"poriginal" .= (Nothing :: Maybe Posting)
] ]
instance ToJSON Transaction instance ToJSON Transaction
@ -93,20 +93,20 @@ instance ToJSON Journal
instance ToJSON Account where instance ToJSON Account where
toJSON a = object toJSON a = object
["aname" .= toJSON (aname a) ["aname" .= aname a
,"aebalance" .= toJSON (aebalance a) ,"aebalance" .= aebalance a
,"aibalance" .= toJSON (aibalance a) ,"aibalance" .= aibalance a
,"anumpostings" .= toJSON (anumpostings a) ,"anumpostings" .= anumpostings a
,"aboring" .= toJSON (aboring a) ,"aboring" .= aboring a
-- To avoid a cycle, show just the parent account's name -- To avoid a cycle, show just the parent account's name
-- in a dummy field. When re-parsed, there will be no parent. -- in a dummy field. When re-parsed, there will be no parent.
,"aparent_" .= toJSON (maybe "" aname $ aparent a) ,"aparent_" .= maybe "" aname (aparent a)
-- Just the names of subaccounts, as a dummy field, ignored when parsed. -- Just the names of subaccounts, as a dummy field, ignored when parsed.
,"asubs_" .= toJSON (map aname $ asubs a) ,"asubs_" .= map aname (asubs a)
-- The actual subaccounts (and their subs..), making a (probably highly redundant) tree -- The actual subaccounts (and their subs..), making a (probably highly redundant) tree
-- ,"asubs" .= toJSON (asubs a) -- ,"asubs" .= asubs a
-- Omit the actual subaccounts -- Omit the actual subaccounts
,"asubs" .= toJSON ([]::[Account]) ,"asubs" .= ([]::[Account])
] ]
deriving instance Generic (Ledger) deriving instance Generic (Ledger)
@ -184,4 +184,4 @@ readJsonFile f = do
-- Example: -- Example:
-- >>> writeJsonFile "out.json" nullmixedamt -- >>> writeJsonFile "out.json" nullmixedamt
writeJsonFile :: ToJSON a => FilePath -> a -> IO () writeJsonFile :: ToJSON a => FilePath -> a -> IO ()
writeJsonFile f v = BL.writeFile f (encode $ toJSON v) writeJsonFile f v = BL.writeFile f (encode v)