How to use Parsers from Aeson with IO
问题 I have data types with many fields that, if not being manually specified by a JSON configuration file, should be randomly set. I am using Aeson to parse the config file. What is the best way to do this? Currently, I am setting values equal to some impossible value, and then later checking for said value to edit. data Example = Example { a :: Int, b :: Int } default = Example 1 2 instance FromJSON Example where parseJSON = withObject "Example" $ \v -> Example <$> (v .: "a" <|> return (a