streaming-utils- http, attoparsec, pipes and conduit utilities for the streaming libraries

Safe HaskellNone



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 Source


AttoparsecError ParsingError

An attoparsec error that happened while parsing the raw JSON string.

FromJSONError String

An aeson error that happened while trying to convert a Value to an FromJSON instance, as reported by Error.

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

Given a bytestring, parse a top level json entity - returning any leftover bytes.

decoded :: (Monad m, FromJSON a) => ByteString m r -> Stream (Of a) m (Either (DecodingError, ByteString m r) r) Source

Resolve a succession of top-level json items into a corresponding stream of Haskell values.

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 closely modelled on parseByteString and parseLazyByteString