Safe Haskell | None |
---|---|
Language | Haskell2010 |
The encode
, decode
and decoded
functions replicate
the similar functions in Renzo Carbonara's `pipes-aeson`.
streamParse
accepts parsers from the 'json-streams' library.
Aeson must consume a whole top level json array or
object before coming to any conclusion. The 'json-streams'
parsers use aeson types, but will stream suitable elements
as they arise.
- data DecodingError
- = AttoparsecError ParsingError
- | FromJSONError String
- encode :: (Monad m, ToJSON a) => a -> ByteString m ()
- decode :: (Monad m, FromJSON a) => StateT (ByteString m x) m (Either DecodingError a)
- decoded :: (Monad m, FromJSON a) => ByteString m r -> Stream (Of a) m (Either (DecodingError, ByteString m r) r)
- streamParse :: Monad m => Parser a -> ByteString m r -> Stream (Of a) m (Maybe String, ByteString m r)
Documentation
data DecodingError Source
AttoparsecError ParsingError | An |
FromJSONError String | An |
encode :: (Monad m, ToJSON a) => a -> ByteString m () Source
This instance allows using errorP
with decoded
and decodedL
instance Error (DecodingError, Producer a m r)
Consecutively parse a
elements from the given Producer
using the given
parser (such as decode
or parseValue
), skipping
any leading whitespace each time.
This Producer
runs until it either runs out of input or until a decoding
failure occurs, in which case it returns Left
with a DecodingError
and
a Producer
with any leftovers. You can use errorP
to turn the
Either
return value into an ErrorT
monad transformer.
Like encode
, except it accepts any ToJSON
instance,
not just Array
or Object
.
decode :: (Monad m, FromJSON a) => StateT (ByteString m x) m (Either DecodingError a) Source
decoded :: (Monad m, FromJSON a) => ByteString m r -> Stream (Of a) m (Either (DecodingError, ByteString m r) r) Source
streamParse :: Monad m => Parser a -> ByteString m r -> Stream (Of a) m (Maybe String, ByteString m r) Source
Experimental. Parse a bytestring with a json-streams
parser.
The function will read through
the whole of a single top level json entity, streaming the valid parses as they
arise. (It will thus for example parse an infinite json bytestring, though these
are rare in practice ...) If the parser is fitted to recognize only one thing,
then zero or one item will be yielded; if it uses combinators like arrayOf
,
it will stream many values as they arise. This function is modelled on
parseByteString
and
parseLazyByteString