on master help sign in
improve example FromJSON instance
ab96025Andrew Martin
Data/Aeson.hs+3−5
@@ -274,11 +274,9 @@ eitherDecodeStrict' =
274-- > {-# LANGUAGE OverloadedStrings #-}
274-- > {-# LANGUAGE OverloadedStrings #-}
275-- >
275-- >
276-- > instance FromJSON Person where
276-- > instance FromJSON Person where
277−-- > parseJSON (Object v) = Person <$>
277+-- > parseJSON = withObject "Person" $ \v -> Person
278−-- > v .: "name" <*>
278+-- > <$> v .: "name"
279−-- > v .: "age"
279+-- > <*> v .: "age"
280−-- > -- A non-Object value is of the wrong type, so fail.
281−-- > parseJSON _ = empty
282--
280--
283-- We can now parse the JSON data like so:
281-- We can now parse the JSON data like so:
284--
282--