Thanks, Michael. When will your suggested approach be more useful than 
something like this below (LBS is Data.ByteString.Lazy, decode is Aeson 
decoder):

decode . LBS.take 27


That is assuming that all of the information stored in the JSON is used up 
- if streaming JSON saves memory by looking at one object at a time, that 
could be more useful. Or if streaming approach fuses better than above 
solution.

On Friday, June 10, 2016 at 5:38:38 PM UTC-4, Michael Thompson wrote:
>
> You can if you like apply aeson/attoparsec parsers directly to a 
> 'streaming bytestring'. 
>
>       import Streaming
>       import qualified Data.ByteString.Streaming.Char8 as Q
>       import qualified Data.ByteString.Streaming.Aeson as Aeson
>       import Data.Aeson 
>       import qualified Data.Attoparsec.ByteString.Streaming as A
>
>
> I can write things like this (note there is the obvious IsString instance 
> for `ByteString m r`):
>
>     >>> (a,b) <- A.parse json' $ void $ Q.splitAt 27 
>  "{\"a\":[1,2],\"b\":[3,4] }      xxxxxxxxxxxxxxxxx"    
>
>     >>> a
>     Left (Object (fromList [("a",Array [Number 1.0,Number 2.0]),("b",Array 
> [Number 3.0,Number 4.0])]))
>
>     >>> Q.length b
>     5 :> ()
>
> Obviously one should take account of where in general the bytes one is not 
> reading were supposed to be coming from and similar questions.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Haskell Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to haskell-pipes+unsubscr...@googlegroups.com.
To post to this group, send email to haskell-pipes@googlegroups.com.

Reply via email to