pipes-aeson-0.4.2: Encode and decode JSON streams using Aeson and Pipes.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Pipes.Aeson.Unchecked

Description

This module exports facilities similar to those exported by the Pipes.Aeson module, except they do not restrict the Values that might be encoded or decoded to be just valid top-level values. That is, not only Objects or Arrays, according to to the RFC-4627 JSON standard.

Synopsis

Encoding

encode :: (Monad m, ToJSON a) => a -> Proxy x' x () ByteString m () Source #

Like encode, except it accepts any ToJSON instance, not just Array or Object. encode :: (Monad m, Ae.ToJSON a) => a -> Producer' B.ByteString m ()

Decoding

decode :: (Monad m, FromJSON a) => Parser ByteString m (Maybe (Either DecodingError a)) Source #

Like decode, except it will decode any FromJSON instance, not just Array or Object.

decoded :: (Monad m, FromJSON a, ToJSON a) => Lens' (Producer ByteString m r) (Producer a m (Either (DecodingError, Producer ByteString m r) r)) Source #

Like decoded, except it will decode and decode any FromJSON and ToJSON instance, not just Array or Object.

loop Source #

Arguments

:: (Monad m, FromJSON a) 
=> (Producer ByteString m r -> Producer ByteString m r)

In case of AttoparsecError, this function will be called to modify the leftovers Producer before using it.

Ideally you will want to drop everything until the beginning of the next JSON element. This is easy to accomplish if there is a clear whitespace delimiter between the JSON elements, such as a newline (i.e., drop 1 . dropWhile (/= 0xA)). However, it can be hard to do correctly is there is no such delimiter. Skipping the first character (i.e., drop 1) should be sufficient in most cases, but not when parsing recursive data structures because you can accidentally parse a child in its parent's stead.

Notice that unless you advance the Producer somehow, loop will never terminate.

-> Producer ByteString m r

Raw JSON input.

-> Producer' (Either DecodingError a) m r 

Repeteadly try to parse raw JSON bytes into a values, reporting any DecodingErrors downstream as they happen.

Including lenghts

decodeL :: (Monad m, FromJSON a) => Parser ByteString m (Maybe (Either DecodingError (Int, a))) Source #

Like decode, except it also returns the length of JSON input that was consumed in order to obtain the value, not including the length of whitespace between each parsed JSON input.

decodedL :: (Monad m, FromJSON a, ToJSON a) => Lens' (Producer ByteString m r) (Producer (Int, a) m (Either (DecodingError, Producer ByteString m r) r)) Source #

Like decoded, except it also tags each decoded entity with the length of JSON input that was consumed in order to obtain the value, not including the length of whitespace between each parsed JSON input.

loopL Source #

Arguments

:: (Monad m, FromJSON a) 
=> (Producer ByteString m r -> Producer ByteString m r)

In case of AttoparsecError, this function will be called to modify the leftovers Producer before using it.

Ideally you will want to drop everything until the beginning of the next JSON element. This is easy to accomplish if there is a clear whitespace delimiter between the JSON elements, such as a newline (i.e., drop 1 . dropWhile (/= 0xA)). However, it can be hard to do correctly is there is no such delimiter. Skipping the first character (i.e., drop 1) should be sufficient in most cases, but not when parsing recursive data structures because you can accidentally parse a child in its parent's stead.

Notice that unless you advance the Producer somehow, loopL will never terminate.

-> Producer ByteString m r

Raw JSON input.

-> Proxy x' x () (Either DecodingError (Int, a)) m r 

Like loop, except it also outputs the length of JSON input that was consumed in order to obtain the value, not including the length of whitespace before nor after the parsed JSON input.