streaming-utils-0.1.1.1: http, attoparsec and pipes utilities for streaming and streaming-bytestring

Safe HaskellNone
LanguageHaskell2010

Data.ByteString.Streaming.Aeson

Description

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.

Synopsis

Documentation

data DecodingError Source

Constructors

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.

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