[Haskell-cafe] JSON parser that returns the rest of the string that was not used

Ryan Newton rrnewton at gmail.com
Sun May 29 21:53:33 UTC 2016


Thanks, I'll have to try it and see if the Parser [Value] can enable
streaming/incremental IO.


On Sun, May 29, 2016 at 1:23 PM, Sanae <uguu at installgentoo.com> wrote:

> You could drop down to the attoparsec layer, but instead of messing with
> IResults, use it to make another parser that will parse all the objects in
> the file.
>
> E.g.  json `sepBy` skipSpace :: Parser [Value]
>
> sepBy and skipSpace both taken from Data.Attoparsec.Text
>
> On Sun, 2016-05-29 at 13:09 -0400, Ryan Newton wrote:
>
> As someone who spent many years putting data in S-expression format, it
> seems natural to me to write multiple S-expressions (or JSON objects) to a
> file, and expect a reader to be able to read them back one at a time.
>
> This seems comparatively uncommon in the JSON world.  Accordingly, it
> looks like the most popular JSON parsing lib, Aeson, doesn't directly
> provide this functionality.  Functions like decode just return a "Maybe a",
> not the left-over input, meaning that you would need to somehow split up
> your multi-object file before attempting to parse, which is annoying and
> error prone.
>
> It looks like maybe you can get Aeson to do what I want by dropping down
> to the attoparsec layer and messing with IResult.
>
> But is there a better way to do this?  Would this be a good convenience
> routine to add to aeson in a PR?  I.e. would anyone else use this?
>
> Thanks,
>   -Ryan
>
>
> _______________________________________________
> Haskell-Cafe mailing listHaskell-Cafe at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160529/a78ceb9b/attachment.html>


More information about the Haskell-Cafe mailing list