on master help sign in
Merge pull request #130 from Peaker/master
e72bcb2Bryan O'Sullivan
Data/Aeson.hs+5−5
@@ -76,7 +76,7 @@ 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, json, json')
79+import Data.Aeson.Parser.Internal (decodeWith, eitherDecodeWith, jsonEOF, json, jsonEOF', json')
80import Data.Aeson.Types
80import Data.Aeson.Types
81import qualified Data.ByteString.Lazy as L
81import qualified Data.ByteString.Lazy as L
82
82
@@ -87,7 +87,7 @@ import qualified Data.ByteString.Lazy as L
87-- This function parses immediately, but defers conversion. See
87-- This function parses immediately, but defers conversion. See
88-- 'json' for details.
88-- 'json' for details.
89decode :: (FromJSON a) => L.ByteString -> Maybe a
89decode :: (FromJSON a) => L.ByteString -> Maybe a
90−decode = decodeWith json fromJSON
90+decode = decodeWith jsonEOF fromJSON
91{-# INLINE decode #-}
91{-# INLINE decode #-}
92
92
93-- | Efficiently deserialize a JSON value from a lazy 'L.ByteString'.
93-- | Efficiently deserialize a JSON value from a lazy 'L.ByteString'.
@@ -97,17 +97,17 @@ decode = decodeWith json fromJSON
97-- This function parses and performs conversion immediately. See
97-- This function parses and performs conversion immediately. See
98-- 'json'' for details.
98-- 'json'' for details.
99decode' :: (FromJSON a) => L.ByteString -> Maybe a
99decode' :: (FromJSON a) => L.ByteString -> Maybe a
100−decode' = decodeWith json' fromJSON
100+decode' = decodeWith jsonEOF' fromJSON
101{-# INLINE decode' #-}
101{-# INLINE decode' #-}
102
102
103-- | Like 'decode' but returns an error message when decoding fails.
103-- | Like 'decode' but returns an error message when decoding fails.
104eitherDecode :: (FromJSON a) => L.ByteString -> Either String a
104eitherDecode :: (FromJSON a) => L.ByteString -> Either String a
105−eitherDecode = eitherDecodeWith json fromJSON
105+eitherDecode = eitherDecodeWith jsonEOF fromJSON
106{-# INLINE eitherDecode #-}
106{-# INLINE eitherDecode #-}
107
107
108-- | Like 'decode'' but returns an error message when decoding fails.
108-- | Like 'decode'' but returns an error message when decoding fails.
109eitherDecode' :: (FromJSON a) => L.ByteString -> Either String a
109eitherDecode' :: (FromJSON a) => L.ByteString -> Either String a
110−eitherDecode' = eitherDecodeWith json' fromJSON
110+eitherDecode' = eitherDecodeWith jsonEOF' fromJSON
111{-# INLINE eitherDecode' #-}
111{-# INLINE eitherDecode' #-}
112
112
113-- $use
113-- $use
Data/Aeson/Parser/Internal.hs+12−2
@@ -15,11 +15,11 @@
15module Data.Aeson.Parser.Internal
15module Data.Aeson.Parser.Internal
16 (
16 (
17 -- * Lazy parsers
17 -- * Lazy parsers
18− json
18+ json, jsonEOF
19 , value
19 , value
20 , jstring
20 , jstring
21 -- * Strict parsers
21 -- * Strict parsers
22− , json'
22+ , json', jsonEOF'
23 , value'
23 , value'
24 -- * Helpers
24 -- * Helpers
25 , decodeWith
25 , decodeWith
@@ -271,3 +271,13 @@ eitherDecodeWith p to s =
271-- The 'json'' and 'value'' parsers combine identification with
271-- The 'json'' and 'value'' parsers combine identification with
272-- conversion. They consume more CPU cycles up front, but have a
272-- conversion. They consume more CPU cycles up front, but have a
273-- smaller memory footprint.
273-- smaller memory footprint.
274+
275+-- | Parse a top-level JSON value followed by optional whitespace and
276+-- end-of-input. See also: 'json'.
277+jsonEOF :: Parser Value
278+jsonEOF = json <* skipSpace <* endOfInput
279+
280+-- | Parse a top-level JSON value followed by optional whitespace and
281+-- end-of-input. See also: 'json''.
282+jsonEOF' :: Parser Value
283+jsonEOF' = json' <* skipSpace <* endOfInput