@@ -281,12 +281,12 @@ genericLiftParseJSON opts pj pjl = fmap to1 . gParseJSON opts (From1Args pj pjl)
282-- The basic ways to signal a failed conversion are as follows:
282-- The basic ways to signal a failed conversion are as follows:
284−-- * 'empty' and 'mzero' work, but are terse and uninformative
284+-- * 'empty' and 'mzero' work, but are terse and uninformative;
286−-- * 'fail' yields a custom error message
286+-- * 'fail' yields a custom error message;
288-- * 'typeMismatch' produces an informative message for cases when the
288-- * '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.
291-- An example type and instance using 'typeMismatch':
291-- An example type and instance using 'typeMismatch':
@@ -296,27 +296,27 @@ genericLiftParseJSON opts pj pjl = fmap to1 . gParseJSON opts (From1Args pj pjl)
297-- data Coord = Coord { x :: Double, y :: Double }
297-- data Coord = Coord { x :: Double, y :: Double }
299−-- instance FromJSON Coord where
299+-- instance 'FromJSON' Coord where
300−-- parseJSON ('Object' v) = Coord
300+-- 'parseJSON' ('Object' v) = Coord
301−-- '<$>' v '.:' \"x\"
301+-- '<$>' v '.:' \"x\"
302-- '<*>' v '.:' \"y\"
302-- '<*>' v '.:' \"y\"
304-- \-- We do not expect a non-'Object' value here.
304-- \-- We do not expect a non-'Object' value here.
305-- \-- We could use 'mzero' to fail, but 'typeMismatch'
305-- \-- We could use 'mzero' to fail, but 'typeMismatch'
306-- \-- gives a much more informative error message.
306-- \-- gives a much more informative error message.
307−-- parseJSON invalid = 'typeMismatch' \"Coord\" invalid
307+-- 'parseJSON' invalid = 'typeMismatch' \"Coord\" invalid
310-- For this common case of only being concerned with a single
310-- 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.
312-- are provided. Their use is to be preferred when possible, since
312-- 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
314-- (assuming the same language extension and data type) as:
314-- (assuming the same language extension and data type) as:
317−-- instance FromJSON Coord where
317+-- instance 'FromJSON' Coord where
318−-- parseJSON = withObject \"Coord\" $ \v -> Coord
318+-- 'parseJSON' = 'withObject' \"Coord\" $ \v -> Coord
319−-- '<$>' v '.:' \"x\"
319+-- '<$>' v '.:' \"x\"
320-- '<*>' v '.:' \"y\"
320-- '<*>' v '.:' \"y\"
@@ -325,7 +325,7 @@ genericLiftParseJSON opts pj pjl = fmap to1 . gParseJSON opts (From1Args pj pjl)
326-- * "Data.Aeson.TH" provides Template Haskell functions which will derive an
326-- * "Data.Aeson.TH" provides Template Haskell functions which will derive an
327-- instance at compile time. The generated instance is optimized for your type
327-- 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.
330-- * The compiler can provide a default generic implementation for
330-- * The compiler can provide a default generic implementation for
331-- 'parseJSON'.
331-- 'parseJSON'.
@@ -343,18 +343,21 @@ genericLiftParseJSON opts pj pjl = fmap to1 . gParseJSON opts (From1Args pj pjl)
344-- data Coord = Coord { x :: Double, y :: Double } deriving 'Generic'
344-- data Coord = Coord { x :: Double, y :: Double } deriving 'Generic'
346−-- instance FromJSON Coord
346+-- instance 'FromJSON' Coord
349−-- If @DefaultSignatures@ doesn't give exactly the results you want,
349+-- The default implementation will be equivalent to
350+-- @parseJSON = 'genericParseJSON' 'defaultOptions'@; If you need different
350−-- you can customize the generic decoding with only a tiny amount of
351+-- options, you can customize the generic decoding by defining:
351−-- effort, using 'genericParseJSON' with your preferred 'Options':
354+-- customOptions = 'defaultOptions'
355+-- { 'fieldLabelModifier' = 'map' 'Data.Char.toUpper'
354−-- instance FromJSON Coord where
358+-- instance 'FromJSON' Coord where
355−-- parseJSON = 'genericParseJSON' 'defaultOptions'
359+-- 'parseJSON' = 'genericParseJSON' customOptions
358class FromJSON a where
361class FromJSON a where
359 parseJSON :: Value -> Parser a
362 parseJSON :: Value -> Parser a
@@ -516,7 +519,7 @@ typeMismatch expected actual =
517-- * "Data.Aeson.TH" provides Template Haskell functions which will derive an
520-- * "Data.Aeson.TH" provides Template Haskell functions which will derive an
518-- instance at compile time. The generated instance is optimized for your type
521-- 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.
521-- * The compiler can provide a default generic implementation for
524-- * The compiler can provide a default generic implementation for
522-- 'liftParseJSON'.
525-- 'liftParseJSON'.
@@ -534,16 +537,20 @@ typeMismatch expected actual =
535-- data Pair a b = Pair { pairFst :: a, pairSnd :: b } deriving 'Generic1'
538-- data Pair a b = Pair { pairFst :: a, pairSnd :: b } deriving 'Generic1'
537−-- instance FromJSON a => FromJSON1 (Pair a)
540+-- instance 'FromJSON' a => 'FromJSON1' (Pair a)
540−-- If @DefaultSignatures@ doesn't give exactly the results you want,
543+-- If the default implementation doesn't give exactly the results you want,
541-- you can customize the generic decoding with only a tiny amount of
544-- you can customize the generic decoding with only a tiny amount of
542-- effort, using 'genericLiftParseJSON' with your preferred 'Options':
545-- effort, using 'genericLiftParseJSON' with your preferred 'Options':
548+-- customOptions = 'defaultOptions'
549+-- { 'fieldLabelModifier' = 'map' 'Data.Char.toUpper'
545−-- instance FromJSON a => FromJSON1 (Pair a) where
552+-- instance 'FromJSON' a => 'FromJSON1' (Pair a) where
546−-- liftParseJSON = 'genericLiftParseJSON' 'defaultOptions'
553+-- 'liftParseJSON' = 'genericLiftParseJSON' customOptions
548class FromJSON1 f where
555class FromJSON1 f where
549 liftParseJSON :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (f a)
556 liftParseJSON :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (f a)
@@ -614,43 +621,44 @@ instance (FromJSON a) => FromJSON [a] where
614-- Functions
621-- Functions
615-------------------------------------------------------------------------------
622-------------------------------------------------------------------------------
617−-- | @withObject expected f value@ applies @f@ to the 'Object' when @value@ is an @Object@
624+-- | @'withObject' expected f value@ applies @f@ to the 'Object' when @value@
618−-- and fails using @'typeMismatch' expected@ otherwise.
625+-- is an 'Object' and fails using @'typeMismatch' expected@ otherwise.
619withObject :: String -> (Object -> Parser a) -> Value -> Parser a
626withObject :: String -> (Object -> Parser a) -> Value -> Parser a
620withObject _ f (Object obj) = f obj
627withObject _ f (Object obj) = f obj
621withObject expected _ v = typeMismatch expected v
628withObject expected _ v = typeMismatch expected v
622{-# INLINE withObject #-}
629{-# INLINE withObject #-}
624−-- | @withText expected f value@ applies @f@ to the 'Text' when @value@ is a @String@
631+-- | @'withText' expected f value@ applies @f@ to the 'Text' when @value@ is a
625−-- and fails using @'typeMismatch' expected@ otherwise.
632+-- 'String' and fails using @'typeMismatch' expected@ otherwise.
626withText :: String -> (Text -> Parser a) -> Value -> Parser a
633withText :: String -> (Text -> Parser a) -> Value -> Parser a
627withText _ f (String txt) = f txt
634withText _ f (String txt) = f txt
628withText expected _ v = typeMismatch expected v
635withText expected _ v = typeMismatch expected v
629{-# INLINE withText #-}
636{-# INLINE withText #-}
631−-- | @withArray expected f value@ applies @f@ to the 'Array' when @value@ is an @Array@
638+-- | @'withArray' expected f value@ applies @f@ to the 'Array' when @value@ is
632−-- and fails using @'typeMismatch' expected@ otherwise.
639+-- an 'Array' and fails using @'typeMismatch' expected@ otherwise.
633withArray :: String -> (Array -> Parser a) -> Value -> Parser a
640withArray :: String -> (Array -> Parser a) -> Value -> Parser a
634withArray _ f (Array arr) = f arr
641withArray _ f (Array arr) = f arr
635withArray expected _ v = typeMismatch expected v
642withArray expected _ v = typeMismatch expected v
636{-# INLINE withArray #-}
643{-# INLINE withArray #-}
638−-- | @withNumber expected f value@ applies @f@ to the 'Number' when @value@ is a 'Number'.
645+-- | @'withNumber' expected f value@ applies @f@ to the 'Number' when @value@
639−-- and fails using @'typeMismatch' expected@ otherwise.
646+-- is a 'Number' and fails using @'typeMismatch' expected@ otherwise.
640withNumber :: String -> (Number -> Parser a) -> Value -> Parser a
647withNumber :: String -> (Number -> Parser a) -> Value -> Parser a
641withNumber expected f = withScientific expected (f . scientificToNumber)
648withNumber expected f = withScientific expected (f . scientificToNumber)
642{-# INLINE withNumber #-}
649{-# INLINE withNumber #-}
643{-# DEPRECATED withNumber "Use withScientific instead" #-}
650{-# DEPRECATED withNumber "Use withScientific instead" #-}
645−-- | @withScientific expected f value@ applies @f@ to the 'Scientific' number when @value@ is a 'Number'.
652+-- | @'withScientific' expected f value@ applies @f@ to the 'Scientific' number
646−-- and fails using @'typeMismatch' expected@ otherwise.
653+-- when @value@ is a 'Number' and fails using @'typeMismatch' expected@
647withScientific :: String -> (Scientific -> Parser a) -> Value -> Parser a
655withScientific :: String -> (Scientific -> Parser a) -> Value -> Parser a
648withScientific _ f (Number scientific) = f scientific
656withScientific _ f (Number scientific) = f scientific
649withScientific expected _ v = typeMismatch expected v
657withScientific expected _ v = typeMismatch expected v
650{-# INLINE withScientific #-}
658{-# INLINE withScientific #-}
652−-- | @withBool expected f value@ applies @f@ to the 'Bool' when @value@ is a @Bool@
660+-- | @'withBool' expected f value@ applies @f@ to the 'Bool' when @value@ is a
653−-- and fails using @'typeMismatch' expected@ otherwise.
661+-- 'Bool' and fails using @'typeMismatch' expected@ otherwise.
654withBool :: String -> (Bool -> Parser a) -> Value -> Parser a
662withBool :: String -> (Bool -> Parser a) -> Value -> Parser a
655withBool _ f (Bool arr) = f arr
663withBool _ f (Bool arr) = f arr
656withBool expected _ v = typeMismatch expected v
664withBool expected _ v = typeMismatch expected v