make database less brittle when something's wrong with the JSON file

This commit is contained in:
Jonathan Lamothe
2020-01-03 21:37:33 -05:00
parent 2768934c7c
commit 3ee97406f1

View File

@@ -528,11 +528,11 @@ makeLenses ''GameStats
instance FromJSON Database where instance FromJSON Database where
parseJSON = withObject "Database" $ \v -> Database parseJSON = withObject "Database" $ \v -> Database
<$> v .: "players" <$> v .:? "players" .!= []
<*> v .: "goalies" <*> v .:? "goalies" .!= []
<*> v .: "games" <*> v .:? "games" .!= 0
<*> v .: "home_game_stats" <*> v .:? "home_game_stats" .!= newGameStats
<*> v .: "away_game_stats" <*> v .:? "away_game_stats" .!= newGameStats
instance ToJSON Database where instance ToJSON Database where
toJSON (Database players goalies games hgs ags) = object toJSON (Database players goalies games hgs ags) = object