@@ -281,12 +281,12 @@ genericLiftParseJSON opts pj pjl = fmap to1 . gParseJSON opts (From1Args pj pjl)
281281--
282282-- The basic ways to signal a failed conversion are as follows:
283283--
284−-- * 'empty' and 'mzero' work, but are terse and uninformative
284+-- * 'empty' and 'mzero' work, but are terse and uninformative;
285285--
286−-- * 'fail' yields a custom error message
286+-- * 'fail' yields a custom error message;
287287--
288288-- * 'typeMismatch' produces an informative message for cases when the
289−-- value encountered is not of the expected type
289+-- value encountered is not of the expected type.
290290--
291291-- An example type and instance using 'typeMismatch':
292292--
@@ -296,27 +296,27 @@ genericLiftParseJSON opts pj pjl = fmap to1 . gParseJSON opts (From1Args pj pjl)
296296--
297297-- data Coord = Coord { x :: Double, y :: Double }
298298--
299−-- instance FromJSON Coord where
300−-- parseJSON ('Object' v) = Coord
301−-- '<$>' v '.:' \"x\"
299+-- instance 'FromJSON' Coord where
300+-- 'parseJSON' ('Object' v) = Coord
301+-- '<$>' v '.:' \"x\"
302302-- '<*>' v '.:' \"y\"
303303--
304304-- \-- We do not expect a non-'Object' value here.
305305-- \-- We could use 'mzero' to fail, but 'typeMismatch'
306306-- \-- gives a much more informative error message.
307−-- parseJSON invalid = 'typeMismatch' \"Coord\" invalid
307+-- 'parseJSON' invalid = 'typeMismatch' \"Coord\" invalid
308308-- @
309309--
310310-- For this common case of only being concerned with a single
311−-- type of JSON value, the functions @withObject@, @withNumber@, etc.
311+-- type of JSON value, the functions 'withObject', 'withNumber', etc.
312312-- are provided. Their use is to be preferred when possible, since
313−-- they are more terse. Using @withObject@, we can rewrite the above instance
313+-- they are more terse. Using 'withObject', we can rewrite the above instance
314314-- (assuming the same language extension and data type) as:
315315--
316316-- @
317−-- instance FromJSON Coord where
318−-- parseJSON = withObject \"Coord\" $ \v -> Coord
319−-- '<$>' v '.:' \"x\"
317+-- instance 'FromJSON' Coord where
318+-- 'parseJSON' = 'withObject' \"Coord\" $ \v -> Coord
319+-- '<$>' v '.:' \"x\"
320320-- '<*>' v '.:' \"y\"
321321-- @
322322--
@@ -325,7 +325,7 @@ genericLiftParseJSON opts pj pjl = fmap to1 . gParseJSON opts (From1Args pj pjl)
325325--
326326-- * "Data.Aeson.TH" provides Template Haskell functions which will derive an
327327-- instance at compile time. The generated instance is optimized for your type
328−-- so will probably be more efficient than the following two options:
328+-- so it will probably be more efficient than the following option.
329329--
330330-- * The compiler can provide a default generic implementation for
331331-- 'parseJSON'.
@@ -343,18 +343,21 @@ genericLiftParseJSON opts pj pjl = fmap to1 . gParseJSON opts (From1Args pj pjl)
343343--
344344-- data Coord = Coord { x :: Double, y :: Double } deriving 'Generic'
345345--
346−-- instance FromJSON Coord
346+-- instance 'FromJSON' Coord
347347-- @
348348--
349−-- If @DefaultSignatures@ doesn't give exactly the results you want,
350−-- you can customize the generic decoding with only a tiny amount of
351−-- effort, using 'genericParseJSON' with your preferred 'Options':
349+-- The default implementation will be equivalent to
350+-- @parseJSON = 'genericParseJSON' 'defaultOptions'@; If you need different
351+-- options, you can customize the generic decoding by defining:
352352--
353353-- @
354−-- instance FromJSON Coord where
355−-- parseJSON = 'genericParseJSON' 'defaultOptions'
354+-- customOptions = 'defaultOptions'
355+-- { 'fieldLabelModifier' = 'map' 'Data.Char.toUpper'
356+-- }
357+--
358+-- instance 'FromJSON' Coord where
359+-- 'parseJSON' = 'genericParseJSON' customOptions
356360-- @
357−
358361class FromJSON a where
359362 parseJSON :: Value -> Parser a
360363
@@ -516,7 +519,7 @@ typeMismatch expected actual =
516519--
517520-- * "Data.Aeson.TH" provides Template Haskell functions which will derive an
518521-- instance at compile time. The generated instance is optimized for your type
519−-- so will probably be more efficient than the following two options:
522+-- so it will probably be more efficient than the following option.
520523--
521524-- * The compiler can provide a default generic implementation for
522525-- 'liftParseJSON'.
@@ -534,16 +537,20 @@ typeMismatch expected actual =
534537--
535538-- data Pair a b = Pair { pairFst :: a, pairSnd :: b } deriving 'Generic1'
536539--
537−-- instance FromJSON a => FromJSON1 (Pair a)
540+-- instance 'FromJSON' a => 'FromJSON1' (Pair a)
538541-- @
539542--
540−-- If @DefaultSignatures@ doesn't give exactly the results you want,
543+-- If the default implementation doesn't give exactly the results you want,
541544-- you can customize the generic decoding with only a tiny amount of
542545-- effort, using 'genericLiftParseJSON' with your preferred 'Options':
543546--
544547-- @
545−-- instance FromJSON a => FromJSON1 (Pair a) where
546−-- liftParseJSON = 'genericLiftParseJSON' 'defaultOptions'
548+-- customOptions = 'defaultOptions'
549+-- { 'fieldLabelModifier' = 'map' 'Data.Char.toUpper'
550+-- }
551+--
552+-- instance 'FromJSON' a => 'FromJSON1' (Pair a) where
553+-- 'liftParseJSON' = 'genericLiftParseJSON' customOptions
547554-- @
548555class FromJSON1 f where
549556 liftParseJSON :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (f a)
@@ -614,43 +621,44 @@ instance (FromJSON a) => FromJSON [a] where
614621-- Functions
615622-------------------------------------------------------------------------------
616623
617−-- | @withObject expected f value@ applies @f@ to the 'Object' when @value@ is an @Object@
618−-- and fails using @'typeMismatch' expected@ otherwise.
624+-- | @'withObject' expected f value@ applies @f@ to the 'Object' when @value@
625+-- is an 'Object' and fails using @'typeMismatch' expected@ otherwise.
619626withObject :: String -> (Object -> Parser a) -> Value -> Parser a
620627withObject _ f (Object obj) = f obj
621628withObject expected _ v = typeMismatch expected v
622629{-# INLINE withObject #-}
623630
624−-- | @withText expected f value@ applies @f@ to the 'Text' when @value@ is a @String@
625−-- and fails using @'typeMismatch' expected@ otherwise.
631+-- | @'withText' expected f value@ applies @f@ to the 'Text' when @value@ is a
632+-- 'String' and fails using @'typeMismatch' expected@ otherwise.
626633withText :: String -> (Text -> Parser a) -> Value -> Parser a
627634withText _ f (String txt) = f txt
628635withText expected _ v = typeMismatch expected v
629636{-# INLINE withText #-}
630637
631−-- | @withArray expected f value@ applies @f@ to the 'Array' when @value@ is an @Array@
632−-- and fails using @'typeMismatch' expected@ otherwise.
638+-- | @'withArray' expected f value@ applies @f@ to the 'Array' when @value@ is
639+-- an 'Array' and fails using @'typeMismatch' expected@ otherwise.
633640withArray :: String -> (Array -> Parser a) -> Value -> Parser a
634641withArray _ f (Array arr) = f arr
635642withArray expected _ v = typeMismatch expected v
636643{-# INLINE withArray #-}
637644
638−-- | @withNumber expected f value@ applies @f@ to the 'Number' when @value@ is a 'Number'.
639−-- and fails using @'typeMismatch' expected@ otherwise.
645+-- | @'withNumber' expected f value@ applies @f@ to the 'Number' when @value@
646+-- is a 'Number' and fails using @'typeMismatch' expected@ otherwise.
640647withNumber :: String -> (Number -> Parser a) -> Value -> Parser a
641648withNumber expected f = withScientific expected (f . scientificToNumber)
642649{-# INLINE withNumber #-}
643650{-# DEPRECATED withNumber "Use withScientific instead" #-}
644651
645−-- | @withScientific expected f value@ applies @f@ to the 'Scientific' number when @value@ is a 'Number'.
646−-- and fails using @'typeMismatch' expected@ otherwise.
652+-- | @'withScientific' expected f value@ applies @f@ to the 'Scientific' number
653+-- when @value@ is a 'Number' and fails using @'typeMismatch' expected@
654+-- otherwise.
647655withScientific :: String -> (Scientific -> Parser a) -> Value -> Parser a
648656withScientific _ f (Number scientific) = f scientific
649657withScientific expected _ v = typeMismatch expected v
650658{-# INLINE withScientific #-}
651659
652−-- | @withBool expected f value@ applies @f@ to the 'Bool' when @value@ is a @Bool@
653−-- and fails using @'typeMismatch' expected@ otherwise.
660+-- | @'withBool' expected f value@ applies @f@ to the 'Bool' when @value@ is a
661+-- 'Bool' and fails using @'typeMismatch' expected@ otherwise.
654662withBool :: String -> (Bool -> Parser a) -> Value -> Parser a
655663withBool _ f (Bool arr) = f arr
656664withBool expected _ v = typeMismatch expected v