Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decode strict bytestrings? #99

jhickner opened this issue Dec 10, 2012 · 2 comments

decode strict bytestrings? #99

jhickner opened this issue Dec 10, 2012 · 2 comments


Copy link

@jhickner jhickner commented Dec 10, 2012

Several times I've run into the situation where I'd like to use Aeson to decode strict bytestrings, as in the case of decoding many very small json files, or when reading from then writing to the same file, in which case the lazy readFile seems to keep the handle open too long in some instances.

I've been using this function, which is just a slight variation on Aeson's decodeWith:

import qualified Data.ByteString as B
import qualified Data.Aeson as A
import qualified Data.Attoparsec as AP

decodeStrict :: A.FromJSON a => B.ByteString -> Maybe a
decodeStrict bs = 
    case AP.parse A.json' bs of
      AP.Done _ v -> case A.fromJSON v of
                       A.Success a -> Just a
                       _            -> Nothing
      _           -> Nothing

It would be nice to have this in the core Aeson package. I can put together a pull request if there's no objection.

Copy link

@alexanderkjeldaas alexanderkjeldaas commented Feb 21, 2013

I found this issue while looking for the same. The Snaplet.Auth.SqliteSimple backend for the auth snaplet in snap has an AuthUser which uses strict ByteStrings. It would be nice to be able to encode/decode to sqlite directly.

Copy link

@ExternalReality ExternalReality commented Jul 13, 2013

Yes, I would also like this feature.

@bos bos closed this Sep 4, 2013
tolysz pushed a commit to tolysz/aeson that referenced this issue May 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants