-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Abusing monadic syntax JSON objects generation. -- -- Generation of big, complex JSON objects with Text.JSON is -- painful. And autoderivation is not always posible. Check documentation -- of Text.JSON.Gen for more info. @package fields-json @version 0.2.2.4 -- | Data structures that hold JSValue inside. Value can be extracted or -- replaced, but is always inside. module Text.JSON.JSValueContainer class JSValueContainer a getJSValue :: JSValueContainer a => a -> JSValue setJSValue :: JSValueContainer a => JSValue -> a -> a instance Text.JSON.JSValueContainer.JSValueContainer Text.JSON.Types.JSValue instance Text.JSON.JSValueContainer.JSValueContainer (Data.Sequence.Internal.Seq (GHC.Base.String, Text.JSON.Types.JSValue)) -- | Interface for extracting data from JSValue. module Text.JSON.FromJSValue -- | Structures that can be parsed from JSON. Instances must -- declare either fromJSValue (parse directly from JSValue) -- or fromJSValueM (uses MonadReader). -- -- Example implementation: -- --
--   data D = D String Int
--   
--   instance FromJSValue D where
--     fromJSValue = do
--       s <- fromJSValue "string_key"
--       i <- fromJSValue "int_key"
--       return (D <$> s <*> i)
--   
-- -- Note that we make use of MonadReader instance for "(->)" and -- of Applicative programming style with <$> and -- <*>. -- -- Note: fromJSValueM is deprecated, in future fromJSValue -- will be generalized to work in any MonadReader JSValue. class FromJSValue a fromJSValue :: FromJSValue a => JSValue -> Maybe a fromJSValueM :: (FromJSValue a, JSValueContainer c, MonadReader c m) => m (Maybe a) -- | Structures that can be parsed from JSON, fields absent in the -- JSON will be filled in using (optional) original structure. -- -- By convention JSON null should be treated as a request to reset -- structure element to default value. class FromJSValueWithUpdate a fromJSValueWithUpdate :: FromJSValueWithUpdate a => Maybe a -> JSValue -> Maybe a fromJSValueWithUpdateM :: (FromJSValueWithUpdate a, JSValueContainer c, MonadReader c m) => Maybe a -> m (Maybe a) -- | Structures that can be matched with JSValue class MatchWithJSValue a matchesWithJSValue :: MatchWithJSValue a => a -> JSValue -> Bool matchesWithJSValueM :: (MatchWithJSValue a, JSValueContainer c, MonadReader c m) => a -> m Bool -- | 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)) -- | Reading the value that is on a field. Semantics are a bit involved, -- example GHCi session should clarify: -- --
--   Prelude> :set -XNoMonomorphismRestriction
--   Prelude> let x = withJSValue (JSObject (toJSObject [("key",JSString $ toJSString "value")]))
--   Prelude> x (fromJSValueField "key") :: IO (Maybe Int)
--   Nothing
--   Prelude> x (fromJSValueField "key") :: IO (Maybe (Maybe Int))
--   Just Nothing
--   Prelude> x (fromJSValueField "key") :: IO (Maybe (Maybe (Maybe Int)))
--   Just (Just Nothing)
--   Prelude> x (fromJSValueField "key") :: IO (Maybe String)
--   Just "value"
--   Prelude> x (fromJSValueField "key") :: IO (Maybe (Maybe String))
--   Just (Just "value")
--   Prelude> x (fromJSValueField "key") :: IO (Maybe (Maybe (Maybe String)))
--   Just (Just (Just "value"))
--   Prelude> let x = withJSValue (JSArray [])
--   Prelude> x (fromJSValueField "key") :: IO (Maybe String)
--   Nothing
--   Prelude> x (fromJSValueField "key") :: IO (Maybe (Maybe String))
--   Nothing
--   Prelude> x (fromJSValueField "key") :: IO (Maybe (Maybe (Maybe String)))
--   Nothing
--   
fromJSValueField :: (JSValueContainer c, MonadReader c m, FromJSValue a) => String -> m (Maybe a) -- | Version of fromJSValueField for Base64 encoded data to avoid -- memory leak. fromJSValueFieldBase64 :: (JSValueContainer c, MonadReader c m) => String -> m (Maybe ByteString) -- | Generalization of fromJSValueField. Does not use -- FromJSValue instances. fromJSValueFieldCustom :: (JSValueContainer c, MonadReader c m) => String -> m (Maybe a) -> m (Maybe a) -- | Runs parser on each element of underlaying json. Returns Just iff JSON -- is array. fromJSValueCustomMany :: (JSValueContainer c, MonadReader c m) => m (Maybe a) -> m (Maybe [a]) -- | Generalization of fromJSValueCustomMany, where each element of -- array can have different parser. fromJSValueCustomList :: (JSValueContainer c, MonadReader c m) => [m (Maybe a)] -> m (Maybe [a]) -- | Runs parser on each element of underlying json. Returns Just -- iff JSON is an array. -- -- Note: This method has quadratic complexity. It is better to write less -- general matching algorithms that use Maps. fromJSValueManyWithUpdate :: (JSValueContainer c, MonadReader c m, FromJSValueWithUpdate a, MatchWithJSValue a) => [a] -> m (Maybe [a]) -- | Simple runner. Example: -- --
--   let (v :: MyStruct) = runIdentity $ withJSValue js (fromJSValueM)
--   
-- -- or inline: -- --
--   let z = runIdentity $ withJSValue js $ do
--               a <- fromJSValueField "a"
--               b <- fromJSValueField "b"
--               c <- fromJSValueField "c"
--               return ((,,) <$> a <*> b <*> <*> c)
--   
-- -- or using the monad transformer: -- --
--   z <- withJSValue js $ do
--               a <- fromJSValueField "a"
--               b <- fromJSValueField "b"
--               c <- fromJSValueField "c"
--               return ((,,) <$> a <*> b <*> c)
--   
withJSValue :: Monad m => JSValue -> ReaderT JSValue m a -> m a instance Text.JSON.FromJSValue.FromJSValue Text.JSON.Types.JSValue instance Text.JSON.FromJSValue.FromJSValue GHC.Base.String instance Text.JSON.FromJSValue.FromJSValue Data.ByteString.Internal.ByteString instance Text.JSON.FromJSValue.FromJSValue GHC.Integer.Type.Integer instance Text.JSON.FromJSValue.FromJSValue GHC.Types.Int instance Text.JSON.FromJSValue.FromJSValue GHC.Int.Int16 instance Text.JSON.FromJSValue.FromJSValue GHC.Int.Int32 instance Text.JSON.FromJSValue.FromJSValue GHC.Int.Int64 instance Text.JSON.FromJSValue.FromJSValue GHC.Types.Bool instance Text.JSON.FromJSValue.FromJSValue GHC.Types.Double instance Text.JSON.FromJSValue.FromJSValue GHC.Types.Float instance Text.JSON.FromJSValue.FromJSValue a => Text.JSON.FromJSValue.FromJSValue [a] instance Text.JSON.FromJSValue.FromJSValue a => Text.JSON.FromJSValue.FromJSValue (GHC.Maybe.Maybe a) instance (Text.JSON.FromJSValue.FromJSValue a, Text.JSON.FromJSValue.FromJSValue b) => Text.JSON.FromJSValue.FromJSValue (a, b) instance (Text.JSON.FromJSValue.FromJSValue a, Text.JSON.FromJSValue.FromJSValue b, Text.JSON.FromJSValue.FromJSValue c) => Text.JSON.FromJSValue.FromJSValue (a, b, c) instance (Text.JSON.FromJSValue.FromJSValue a, Text.JSON.FromJSValue.FromJSValue b, Text.JSON.FromJSValue.FromJSValue c, Text.JSON.FromJSValue.FromJSValue d) => Text.JSON.FromJSValue.FromJSValue (a, b, c, d) instance (Text.JSON.FromJSValue.FromJSValue a, Text.JSON.FromJSValue.FromJSValue b, Text.JSON.FromJSValue.FromJSValue c, Text.JSON.FromJSValue.FromJSValue d, Text.JSON.FromJSValue.FromJSValue e) => Text.JSON.FromJSValue.FromJSValue (a, b, c, d, e) instance (Text.JSON.FromJSValue.FromJSValue a, Text.JSON.FromJSValue.FromJSValue b, Text.JSON.FromJSValue.FromJSValue c, Text.JSON.FromJSValue.FromJSValue d, Text.JSON.FromJSValue.FromJSValue e, Text.JSON.FromJSValue.FromJSValue f) => Text.JSON.FromJSValue.FromJSValue (a, b, c, d, e, f) -- | Unifing some structures so they can be serialized to JSValue module Text.JSON.ToJSValue class ToJSValue a toJSValue :: ToJSValue a => a -> JSValue instance Text.JSON.ToJSValue.ToJSValue Text.JSON.Types.JSValue instance Text.JSON.ToJSValue.ToJSValue GHC.Types.Bool instance Text.JSON.ToJSValue.ToJSValue GHC.Base.String instance GHC.Real.Real a => Text.JSON.ToJSValue.ToJSValue a instance Text.JSON.ToJSValue.ToJSValue a => Text.JSON.ToJSValue.ToJSValue [a] instance Text.JSON.ToJSValue.ToJSValue a => Text.JSON.ToJSValue.ToJSValue (Data.Map.Internal.Map GHC.Base.String a) instance Text.JSON.ToJSValue.ToJSValue a => Text.JSON.ToJSValue.ToJSValue (GHC.Maybe.Maybe a) instance (Text.JSON.ToJSValue.ToJSValue a, Text.JSON.ToJSValue.ToJSValue b) => Text.JSON.ToJSValue.ToJSValue (a, b) -- | Abusing monadic 'do' notation library for generating JSON object. -- Hard-bound to JSValue from json package from hackage. -- -- Main ideas -- -- -- --
--   runJSONGen $ do
--       value "a" "a"
--       value "b" [1,2,3]
--       object "c" $ do
--           value "x" True
--           value "y" False
--   
-- -- Will generate json object: -- --
--   {a : "a", b: [1,2,3], c: {x: true, y : false}}
--   
module Text.JSON.Gen -- | Basic types type JSONGen = JSONGenT Identity data JSONGenT m a -- | Simple runner runJSONGen :: JSONGen () -> JSValue runJSONGenT :: Monad m => JSONGenT m () -> m JSValue -- | Set pure value under given name in final JSON object value :: (Monad m, ToJSValue a) => String -> a -> JSONGenT m () -- | Monadic verion of value valueM :: (Monad m, ToJSValue a) => String -> m a -> JSONGenT m () -- | Embed other JSON object as field in resulting JSON object. object :: Monad m => String -> JSONGenT m () -> JSONGenT m () -- | Version for lists of objects. objects :: Monad m => String -> [JSONGenT m ()] -> JSONGenT m () instance Control.Monad.Trans.Class.MonadTrans Text.JSON.Gen.JSONGenT instance GHC.Base.Monad m => GHC.Base.Monad (Text.JSON.Gen.JSONGenT m) instance GHC.Base.Functor m => GHC.Base.Functor (Text.JSON.Gen.JSONGenT m) instance GHC.Base.Monad m => GHC.Base.Applicative (Text.JSON.Gen.JSONGenT m) instance GHC.Base.Monad m => Control.Monad.Reader.Class.MonadReader (Data.Sequence.Internal.Seq (GHC.Base.String, Text.JSON.Types.JSValue)) (Text.JSON.Gen.JSONGenT m) instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Text.JSON.Gen.JSONGenT m)