@@ -43,6 +43,7 @@ import Control.Applicative ((<$>), (<*>), pure)
4343import Data.Aeson.Functions
4444import Data.Aeson.Types.Internal
4545import Data.Attoparsec.Char8 (Number(..))
46+import Data.Fixed
4647import Data.Hashable (Hashable(..))
4748import Data.Int (Int8, Int16, Int32, Int64)
4849import Data.Maybe (fromMaybe)
@@ -305,6 +306,17 @@ instance FromJSON (Ratio Integer) where
305306 parseJSON v = typeMismatch "Ratio Integer" v
306307 {-# INLINE parseJSON #-}
307308
309+instance HasResolution a => ToJSON (Fixed a) where
310+ toJSON = Number . realToFrac
311+ {-# INLINE toJSON #-}
312+
313+instance HasResolution a => FromJSON (Fixed a) where
314+ parseJSON (Number n) = pure $ case n of
315+ D d -> realToFrac d
316+ I i -> fromIntegral i
317+ parseJSON v = typeMismatch "Fixed" v
318+ {-# INLINE parseJSON #-}
319+
308320instance ToJSON Int where
309321 toJSON = Number . fromIntegral
310322 {-# INLINE toJSON #-}