Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
decode strict bytestrings? #99
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
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.