@@ -61,7 +61,7 @@ import Data.Hashable (Hashable(..))
6161import Data.Int (Int8, Int16, Int32, Int64)
6262import Data.Maybe (fromMaybe)
6363import Data.Monoid (Dual(..), First(..), Last(..), mappend)
64−import Data.Ratio (Ratio)
64+import Data.Ratio (Ratio, (%), numerator, denominator)
6565import Data.Text (Text, pack, unpack)
6666import Data.Text.Encoding (encodeUtf8)
6767import Data.Time (UTCTime, ZonedTime(..), TimeZone(..))
@@ -343,14 +343,15 @@ instance FromJSON Float where
343343 {-# INLINE parseJSON #-}
344344
345345instance ToJSON (Ratio Integer) where
346− toJSON = Number . fromRational
346+ toJSON r = object [ "numerator" .= numerator r
347+ , "denominator" .= denominator r
348+ ]
347349 {-# INLINE toJSON #-}
348350
349351instance FromJSON (Ratio Integer) where
350− parseJSON = withNumber "Ration Integer" $ \n ->
351− pure $ case n of
352− D d -> toRational d
353− I i -> fromIntegral i
352+ parseJSON = withObject "Rational" $ \obj ->
353+ (%) <$> obj .: "numerator"
354+ <*> obj .: "denominator"
354355 {-# INLINE parseJSON #-}
355356
356357instance HasResolution a => ToJSON (Fixed a) where