on master help sign in
Doc improvements.
commit84e773bcf134d8320bf6eef2a95277943b89eafd authorBryan O'Sullivan <bos@serpentine.com> dateTue 20 Sep 2011, 16:02 (15 years ago) parent9ca5e71
3 files changed+39−10
Data/Aeson.hs+8−6 Data/Aeson/Types/Internal.hs+28−4 aeson.cabal+3
Data/Aeson.hs+8−6
@@ -12,8 +12,11 @@
1212
1313module Data.Aeson
1414 (
15+ -- * Encoding and decoding
16+ decode
17+ , encode
1518 -- * Core JSON types
16− Value(..)
19+ , Value(..)
1720 , Array
1821 , Object
1922 -- * Convenience types
@@ -28,20 +31,19 @@ module Data.Aeson
2831 , (.:)
2932 , (.:?)
3033 , object
31− -- * Encoding and decoding
32− , decode
33− , encode
3434 -- * Parsing
3535 , json
3636 ) where
3737
38−import Data.Aeson.Encode
39−import Data.Aeson.Parser
38+import Data.Aeson.Encode (encode)
39+import Data.Aeson.Parser (json)
4040import Data.Aeson.Types
4141import qualified Data.ByteString.Lazy as L
4242import qualified Data.Attoparsec.Lazy as L
4343
4444-- | Efficiently deserialize a JSON value from a lazy 'L.ByteString'.
45+-- If this fails due to incomplete or invalid input, 'Nothing' is
46+-- returned.
4547decode :: (FromJSON a) => L.ByteString -> Maybe a
4648decode s = case L.parse json s of
4749 L.Done _ v -> case fromJSON v of
Data/Aeson/Types/Internal.hs+28−4
@@ -304,13 +304,25 @@ object = Object . M.fromList
304304--
305305-- An example type and instance:
306306--
307−-- @data Coord { x :: Double, y :: Double }
307+-- @{-\# LANGUAGE OverloadedStrings #-}
308+--
309+-- data Coord { x :: Double, y :: Double }
308310--
309311-- instance ToJSON Coord where
310312-- toJSON (Coord x y) = 'object' [\"x\" '.=' x, \"y\" '.=' y]
311313-- @
312314--
313−-- This example assumes the OverloadedStrings language option is enabled.
315+-- We use the @OverloadedStrings@ language extension so that we can
316+-- write 'Text' values as normal double-quoted strings.
317+--
318+-- If you do not want to write your own 'ToJSON' instances, you have
319+-- two options:
320+--
321+-- * The 'Data.Aeson.TH' module will automatically derive an instance
322+-- for you with a single line of code.
323+--
324+-- * The 'Data.Aeson.Generic' module will work with most data types
325+-- that are instances of 'Data' (but note, this can be slow).
314326class ToJSON a where
315327 toJSON :: a -> Value
316328
@@ -328,7 +340,9 @@ class ToJSON a where
328340--
329341-- An example type and instance:
330342--
331−-- @data Coord { x :: Double, y :: Double }
343+-- @{-\# LANGUAGE OverloadedStrings #-}
344+--
345+-- data Coord { x :: Double, y :: Double }
332346--
333347-- instance FromJSON Coord where
334348-- parseJSON ('Object' v) = Coord '<$>'
@@ -339,7 +353,17 @@ class ToJSON a where
339353-- parseJSON _ = 'mzero'
340354-- @
341355--
342−-- This example assumes the OverloadedStrings language option is enabled.
356+-- We use the @OverloadedStrings@ language extension so that we can
357+-- write 'Text' values as normal double-quoted strings.
358+--
359+-- If you do not want to write your own 'FromJSON' instances, you have
360+-- two options:
361+--
362+-- * The 'Data.Aeson.TH' module will automatically derive an instance
363+-- for you with a single line of code.
364+--
365+-- * The 'Data.Aeson.Generic' module will work with most data types
366+-- that are instances of 'Data' (but note, this can be slow).
343367class FromJSON a where
344368 parseJSON :: Value -> Parser a
345369
aeson.cabal+3
@@ -17,6 +17,9 @@ description:
1717 A JSON parsing and encoding library optimized for ease of use
1818 and high performance.
1919 .
20+ To get started, see the documentation for the @Data.Aeson@ module
21+ below.
22+ .
2023 /Note/: if you use GHCi or Template Haskell, please see the
2124 @README@ file for important details about building this package,
2225 and other packages that depend on it: