on master help sign in
Clarify decode docs
7ab286fBryan O'Sullivan
Data/Aeson.hs+14−1
@@ -76,7 +76,8 @@ module Data.Aeson
76 ) where
76 ) where
77
77
78import Data.Aeson.Encode (encode)
78import Data.Aeson.Encode (encode)
79−import Data.Aeson.Parser.Internal (decodeWith, eitherDecodeWith, jsonEOF, json, jsonEOF', json')
79+import Data.Aeson.Parser.Internal (decodeWith, eitherDecodeWith, jsonEOF, json,
80+ jsonEOF', json')
80import Data.Aeson.Types
81import Data.Aeson.Types
81import qualified Data.ByteString.Lazy as L
82import qualified Data.ByteString.Lazy as L
82
83
@@ -84,6 +85,12 @@ import qualified Data.ByteString.Lazy as L
84-- If this fails due to incomplete or invalid input, 'Nothing' is
85-- If this fails due to incomplete or invalid input, 'Nothing' is
85-- returned.
86-- returned.
86--
87--
88+-- The input must consist solely of a JSON document, with no trailing
89+-- data except for whitespace. This restriction is necessary to ensure
90+-- that if data is being lazily read from a file handle, the file
91+-- handle will be closed in a timely fashion once the document has
92+-- been parsed.
93+--
87-- This function parses immediately, but defers conversion. See
94-- This function parses immediately, but defers conversion. See
88-- 'json' for details.
95-- 'json' for details.
89decode :: (FromJSON a) => L.ByteString -> Maybe a
96decode :: (FromJSON a) => L.ByteString -> Maybe a
@@ -94,6 +101,12 @@ decode = decodeWith jsonEOF fromJSON
94-- If this fails due to incomplete or invalid input, 'Nothing' is
101-- If this fails due to incomplete or invalid input, 'Nothing' is
95-- returned.
102-- returned.
96--
103--
104+-- The input must consist solely of a JSON document, with no trailing
105+-- data except for whitespace. This restriction is necessary to ensure
106+-- that if data is being lazily read from a file handle, the file
107+-- handle will be closed in a timely fashion once the document has
108+-- been parsed.
109+--
97-- This function parses and performs conversion immediately. See
110-- This function parses and performs conversion immediately. See
98-- 'json'' for details.
111-- 'json'' for details.
99decode' :: (FromJSON a) => L.ByteString -> Maybe a
112decode' :: (FromJSON a) => L.ByteString -> Maybe a