Is it possible to parse a Data.Decimal from JSON using the Aeson package?
Suppose I have the following JSON:
{
"foo": 5.231,
"bar": "smth"
}
And the following record type:
data test { foo :: Data.Decimal
, bar :: String } deriving Generic
with
instance FromJSON test
instance ToJSON test
This would work, if it weren't for the Data.Decimal
value "foo".
From what I understand I would need to manually create a FromJSON
and ToJSON
(for converting back to JSON) instance of Data.Decimal, since it doesn't derive from Generic. How can I do that?
Thanks in advance.
I know this is an old thread, but might help someone. Here is how I am converting Decimal to/from json (I assembled this code from a bunch of other code which I don't have the source for now):