on master help sign in
improve example FromJSON instance
commitab960255fd0583a33094d6de3fa98bd8aee1d96c authorAndrew Martin <andrew.thaddeus@gmail.com> dateTue 7 Feb 2017, 14:12 (10 years ago) parentd470ac6
1 file changed+3−5
Data/Aeson.hs+3−5
Data/Aeson.hs+3−5
@@ -274,11 +274,9 @@ eitherDecodeStrict' =
274274-- > {-# LANGUAGE OverloadedStrings #-}
275275-- >
276276-- > instance FromJSON Person where
277−-- > parseJSON (Object v) = Person <$>
278−-- > v .: "name" <*>
279−-- > v .: "age"
280−-- > -- A non-Object value is of the wrong type, so fail.
281−-- > parseJSON _ = empty
277+-- > parseJSON = withObject "Person" $ \v -> Person
278+-- > <$> v .: "name"
279+-- > <*> v .: "age"
282280--
283281-- We can now parse the JSON data like so:
284282--