webdriver-0.1: a Haskell client for the Selenium WebDriver protocol

Safe HaskellSafe-Infered

Test.WebDriver.JSON

Contents

Description

A collection of convenience functions for using and parsing JSON valus within WD. All monadic parse errors are converted to asynchronous BadJSON exceptions.

Synopsis

Access a JSON object key

(!:) :: FromJSON a => Object -> Text -> WD aSource

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' :: FromJSON a => ByteString -> WD aSource

Parse a lazy ByteString as a top-level JSON Value, then convert it to an instance of FromJSON..

fromJSON' :: FromJSON a => Value -> WD aSource

Convert a JSON Value to an instance of FromJSON.

Tuple functions

Convenience functions for working with tuples.

JSON object constructors

single :: ToJSON a => Text -> a -> ValueSource

Construct a singleton JSON object from a key and value.

pair :: (ToJSON a, ToJSON b) => (Text, Text) -> (a, b) -> ValueSource

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) -> ValueSource

Construct a 3-element JSON object from a triple of keys and a triple of values.

Extracting JSON objects into tuples

parsePair :: (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 fourth string is the name of the calling function, for better error reporting.

parseTriple :: (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 :: FromJSON a => Result Value -> WD aSource

Convert an attoparsec parser result to WD.

aesonResultToWD :: Result a -> WD aSource

Convert an Aeson parser result to WD.