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.
The text was updated successfully, but these errors were encountered: