fields-json 0.2.1.1 → 0.2.2
raw patch · 2 files changed
+12/−1 lines, 2 filesnew-uploaderPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Text.JSON.FromJSValue: jsValueField :: (JSValueContainer c, MonadReader c m, FromJSValue a) => String -> m (Maybe (Maybe a))
Files
- fields-json.cabal +1/−1
- src/Text/JSON/FromJSValue.hs +11/−0
fields-json.cabal view
@@ -1,5 +1,5 @@ Name: fields-json-Version: 0.2.1.1+Version: 0.2.2 Synopsis: Abusing monadic syntax JSON objects generation. Description:
src/Text/JSON/FromJSValue.hs view
@@ -16,6 +16,7 @@ -- * Basic Parsing FromJSValue(..) -- * Data Extraction+ , jsValueField , fromJSValueField , fromJSValueFieldBase64 , fromJSValueFieldCustom@@ -88,6 +89,16 @@ askJSValue :: (JSValueContainer c , MonadReader c m) => m JSValue askJSValue = liftM getJSValue ask ++-- | Reading the value that is on some field. Returns 'Nothing' if+-- JSON is not an object or field is present but cannot be parsed,+-- 'Just Nothing' if absent, and 'Just (Just a)' otherwise+jsValueField :: (JSValueContainer c , MonadReader c m, FromJSValue a) => String -> m (Maybe (Maybe a))+jsValueField s = askJSValue >>= fromObject+ where+ fromObject (JSObject object) = case lookup s (fromJSObject object) of Nothing -> return (Just Nothing)+ Just a -> return (Just `fmap` fromJSValue a)+ fromObject _ = return Nothing -- | Reading the value that is on some field. With field if current JSON is not object fromJSValueField :: (JSValueContainer c , MonadReader c m, FromJSValue a) => String -> m (Maybe a)