module Network.AWS.Data.Internal.JSON
(
FromJSON (..)
, parseJSONText
, withObject
, (.:)
, (.:?)
, (.:>)
, (.:?>)
, ToJSON (..)
, toJSONText
, object
, (.=)
) where
import Data.Aeson.Types
import qualified Data.HashMap.Strict as Map
import Data.Text (Text)
import Network.AWS.Data.Internal.Text
parseJSONText :: FromText a => String -> Value -> Parser a
parseJSONText n = withText n (either fail return . fromText)
toJSONText :: ToText a => a -> Value
toJSONText = String . toText
(.:>) :: FromJSON a => Object -> Text -> Either String a
(.:>) o k =
case Map.lookup k o of
Nothing -> Left $ "key " ++ show k ++ " not present"
Just v -> parseEither parseJSON v
(.:?>) :: FromJSON a => Object -> Text -> Either String (Maybe a)
(.:?>) o k =
case Map.lookup k o of
Nothing -> Right Nothing
Just v -> parseEither parseJSON v