aeson-better-errors 0.1.0.1 → 0.2.0.0
raw patch · 2 files changed
+11/−3 lines, 2 filesdep ~bytestringPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: bytestring
API changes (from Hackage documentation)
+ Data.Aeson.BetterErrors.Internal: eachInObjectWithKey :: (Text -> Either err k) -> Parse err a -> Parse err [(k, a)]
Files
aeson-better-errors.cabal view
@@ -1,5 +1,5 @@ name: aeson-better-errors-version: 0.1.0.1+version: 0.2.0.0 synopsis: Better error messages when decoding JSON values. license: MIT license-file: LICENSE
src/Data/Aeson/BetterErrors/Internal.hs view
@@ -160,7 +160,7 @@ displaySpecifics _ (WrongType t val) = [ "Type mismatch:" , "Expected a value of type " <> displayJSONType t- , "Got: " <> decodeUtf8 (BL.toStrict (A.encode val))+ , "Got: " <> decodeUtf8 (B.concat (BL.toChunks (A.encode val))) ] displaySpecifics _ (ExpectedIntegral x) = [ "Expected an integral value, got " <> tshow x ]@@ -307,13 +307,21 @@ forM xs $ \(i, x) -> local (appendPath (ArrayIndex i) . setValue x) p --- | Attempt to parse each property value in the array with the given parser,+-- | Attempt to parse each property value in the object with the given parser, -- and collect the results. eachInObject :: Parse err a -> Parse err [(Text, a)] eachInObject p = do xs <- HashMap.toList <$> asObject forM xs $ \(k, x) -> (k,) <$> local (appendPath (ObjectKey k) . setValue x) p++-- | Attempt to parse each property in the object: parse the key with the+-- given validation function, parse the value with the given parser, and+-- collect the results.+eachInObjectWithKey :: (Text -> Either err k) -> Parse err a -> Parse err [(k, a)]+eachInObjectWithKey parseKey parseVal =+ eachInObject parseVal+ >>= mapM ((\(k,v) -> liftEither ((,) <$> parseKey k <*> pure v))) -- | Lifts a function attempting to validate an arbitrary JSON value into a -- parser. You should only use this if absolutely necessary; the other