Safe Haskell | None |
---|---|
Language | Haskell2010 |
A collection of convenience functions for using and parsing JSON values
within WD
. All monadic parse errors are converted to asynchronous
BadJSON
exceptions.
These functions are used internally to implement webdriver commands, and may be useful for implementing non-standard commands.
- (!:) :: (MonadBaseControl IO wd, FromJSON a) => Object -> Text -> wd a
- (.:??) :: FromJSON a => Object -> Text -> Parser (Maybe a)
- parseJSON' :: MonadBaseControl IO wd => FromJSON a => ByteString -> wd a
- fromJSON' :: MonadBaseControl IO wd => FromJSON a => Value -> wd a
- single :: ToJSON a => Text -> a -> Value
- pair :: (ToJSON a, ToJSON b) => (Text, Text) -> (a, b) -> Value
- triple :: (ToJSON a, ToJSON b, ToJSON c) => (Text, Text, Text) -> (a, b, c) -> Value
- parsePair :: (MonadBaseControl IO wd, FromJSON a, FromJSON b) => String -> String -> String -> Value -> wd (a, b)
- parseTriple :: (MonadBaseControl IO wd, FromJSON a, FromJSON b, FromJSON c) => String -> String -> String -> String -> Value -> wd (a, b, c)
- apResultToWD :: (MonadBaseControl IO wd, FromJSON a) => Result Value -> wd a
- aesonResultToWD :: MonadBaseControl IO wd => Result a -> wd a
- newtype BadJSON = BadJSON String
- data NoReturn = NoReturn
- noReturn :: WebDriver wd => wd NoReturn -> wd ()
- ignoreReturn :: WebDriver wd => wd Value -> wd ()
Access a JSON object key
(!:) :: (MonadBaseControl IO wd, FromJSON a) => Object -> Text -> wd a Source
This operator is a wrapper over Aeson's .:
operator.
Conversion from JSON within WD
Apostrophes are used to disambiguate these functions from their Data.Aeson counterparts.
parseJSON' :: MonadBaseControl IO wd => FromJSON a => ByteString -> wd a Source
Parse a lazy ByteString
as a top-level JSON Value
, then convert it to an
instance of FromJSON
..
Tuple functions
Convenience functions for working with tuples.
JSON object constructors
single :: ToJSON a => Text -> a -> Value Source
Construct a singleton JSON object
from a key and value.
pair :: (ToJSON a, ToJSON b) => (Text, Text) -> (a, b) -> Value Source
Construct a 2-element JSON object
from a pair of keys and a pair of
values.
triple :: (ToJSON a, ToJSON b, ToJSON c) => (Text, Text, Text) -> (a, b, c) -> Value Source
Construct a 3-element JSON object
from a triple of keys and a triple of
values.
Extracting JSON objects into tuples
parsePair :: (MonadBaseControl IO wd, FromJSON a, FromJSON b) => String -> String -> String -> Value -> wd (a, b) Source
Parse a JSON Object
as a pair. The first two string arguments specify the
keys to extract from the object. The third string is the name of the
calling function, for better error reporting.
parseTriple :: (MonadBaseControl IO wd, FromJSON a, FromJSON b, FromJSON c) => String -> String -> String -> String -> Value -> wd (a, b, c) Source
Parse a JSON Object as a triple. The first three string arguments specify the keys to extract from the object. The fourth string is the name of the calling function, for better error reporting.
Conversion from parser results to WD
These functions are used to implement the other functions in this module, and could be used to implement other JSON convenience functions
apResultToWD :: (MonadBaseControl IO wd, FromJSON a) => Result Value -> wd a Source
Convert an attoparsec parser result to WD
.
aesonResultToWD :: MonadBaseControl IO wd => Result a -> wd a Source
Convert an Aeson parser result to WD
.
Parse exception
An error occured when parsing a JSON value.
parsing commands with no return value
A type indicating that we expect no return value from the webdriver request. Its FromJSON instance parses successfully for any values that indicate lack of a return value (a notion that varies from server to server).
noReturn :: WebDriver wd => wd NoReturn -> wd () Source
Convenience function to handle webdriver commands with no return value.
ignoreReturn :: WebDriver wd => wd Value -> wd () Source
Convenience function to ignore result of a webdriver command.