-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | A combinator library on top of a generalised JSON type
--
-- A combinator library on top of a generalised JSON type. The
-- highest-level module is Text.JSON.Combinator and it is
-- expected that no other module need to be explicitly imported.
--
-- Instances for the combinators are provided for two libraries available
-- on hackage:
--
--
-- - json (Text.JSON)
-- - JSONb (Text.JSONb)
--
@package JSON-Combinator
@version 0.2.4
-- | Data structures that used to denote failure of accessing JSON values.
module Text.JSON.Failure
-- | An object field was attempted to access but the object has no such
-- field.
data NoSuchField z
NoSuchField :: z -> NoSuchField z
-- | The JSON value was expected to be an object but it wasn't.
data ExpectedObject j
ExpectedObject :: j -> ExpectedObject j
-- | The JSON value was expected to be a boolean but it wasn't.
data ExpectedBool j
ExpectedBool :: j -> ExpectedBool j
-- | The JSON value was expected to be a number but it wasn't.
data ExpectedNumber j
ExpectedNumber :: j -> ExpectedNumber j
-- | The JSON value was expected to be a string but it wasn't.
data ExpectedString j
ExpectedString :: j -> ExpectedString j
-- | The JSON value was expected to be an array but it wasn't.
data ExpectedArray j
ExpectedArray :: j -> ExpectedArray j
data NoSuchFieldOrExpectedObject z j
NoSuchFieldOrExpectedObject :: (forall x. (NoSuchField z -> x) -> (ExpectedObject j -> x) -> x) -> NoSuchFieldOrExpectedObject z j
instance Typeable1 ExpectedString
instance Typeable1 ExpectedNumber
instance Typeable1 ExpectedBool
instance Typeable1 ExpectedArray
instance Typeable1 ExpectedObject
instance Typeable1 NoSuchField
instance Eq j => Eq (ExpectedString j)
instance Ord j => Ord (ExpectedString j)
instance Show j => Show (ExpectedString j)
instance Data j => Data (ExpectedString j)
instance Eq j => Eq (ExpectedNumber j)
instance Ord j => Ord (ExpectedNumber j)
instance Show j => Show (ExpectedNumber j)
instance Data j => Data (ExpectedNumber j)
instance Eq j => Eq (ExpectedBool j)
instance Ord j => Ord (ExpectedBool j)
instance Show j => Show (ExpectedBool j)
instance Data j => Data (ExpectedBool j)
instance Eq j => Eq (ExpectedArray j)
instance Ord j => Ord (ExpectedArray j)
instance Show j => Show (ExpectedArray j)
instance Data j => Data (ExpectedArray j)
instance Eq j => Eq (ExpectedObject j)
instance Ord j => Ord (ExpectedObject j)
instance Show j => Show (ExpectedObject j)
instance Data j => Data (ExpectedObject j)
instance Eq z => Eq (NoSuchField z)
instance Ord z => Ord (NoSuchField z)
instance Show z => Show (NoSuchField z)
instance Data z => Data (NoSuchField z)
-- | A generalisation on functions to read and write files.
module Text.JSON.InteractFile
class InteractFile z
readFile' :: InteractFile z => FilePath -> IO z
writeFile' :: InteractFile z => FilePath -> z -> IO ()
instance InteractFile ByteString
instance InteractFile [Char]
-- | A generalisation on functions to interact with standard input and
-- standard output.
module Text.JSON.Interact
class Interact z
getContents' :: Interact z => IO z
putStr' :: Interact z => z -> IO ()
interact' :: Interact z => (z -> z) -> IO ()
instance Interact ByteString
instance Interact [Char]
-- | Pretty-printing JSON values.
module Text.JSON.JSONPrint
-- | Pretty-printing JSON values.
class JSONPrint j s | j -> s
printJSON :: JSONPrint j s => j -> s
instance JSONPrint Json [Char]
instance JSONPrint JSValue [Char]
instance JSONPrint JSON ByteString
-- | Prepending values to existing JSON association values.
module Text.JSON.JSONPrepend
-- | Prepending values to existing JSON association values.
class JSONPrepend j s | j -> s
(->:) :: JSONPrepend j s => (s, j) -> j -> j
(-->>:) :: JSONPrepend j s => j -> j -> j
instance JSONPrepend Json [Char]
instance JSONPrepend JSValue [Char]
instance JSONPrepend JSON ByteString
-- | Parsing JSON object values.
module Text.JSON.JSONParse
-- | Parsing JSON object values.
class JSONParse j p e | j -> p, j -> e
parseJSON :: JSONParse j p e => String -> p -> Either e j
-- | Parse a value with an empty source name.
parseJSON' :: JSONParse j p e => p -> Either e j
instance JSONParse Json [Char] ParseError
instance JSONParse JSValue [Char] ParseError
instance JSONParse JSON ByteString [Char]
-- | The base functions for accessing JSON object fields.
module Text.JSON.JSONField
-- | Accessing JSON object fields.
class JSONField j f | j -> f
field :: (JSONField j f, Failure (NoSuchFieldOrExpectedObject f j) m) => f -> j -> m j
fields :: (JSONField j f, Failure (ExpectedObject j) m) => j -> m [f]
values :: (JSONField j f, Failure (ExpectedObject j) m) => j -> m [j]
instance JSONField Json [Char]
instance JSONField JSValue [Char]
instance JSONField JSON ByteString
-- | The generalisation of a JSON object.
module Text.JSON.JSONLike
-- | The generalisation of a JSON object.
class JSONLike j s a o | j -> s, j -> a, j -> o
foldJSON :: JSONLike j s a o => x -> x -> x -> (Rational -> x) -> (s -> x) -> (a j -> x) -> (o j -> x) -> j -> x
jnull :: JSONLike j s a o => j
jtrue :: JSONLike j s a o => j
jfalse :: JSONLike j s a o => j
jnumber :: JSONLike j s a o => Rational -> j
jstring :: JSONLike j s a o => s -> j
jarray :: JSONLike j s a o => a j -> j
jobject :: JSONLike j s a o => o j -> j
newtype StringMap a
StringMap :: Map String a -> StringMap a
runStringMap :: StringMap a -> Map String a
instance Typeable1 StringMap
instance Eq a => Eq (StringMap a)
instance Show a => Show (StringMap a)
instance Read a => Read (StringMap a)
instance Functor StringMap
instance Foldable StringMap
instance Traversable StringMap
instance Monoid (StringMap a)
instance Data a => Data (StringMap a)
instance Functor JSObject
instance JSONLike Json [Char] [] StringMap
instance JSONLike JSValue [Char] [] JSObject
instance JSONLike JSON ByteString [] Trie
-- | Combinators for JSON data types.
module Text.JSON.Combinator
-- | Inverts the JSON value if it is a boolean.
jnot :: JSONLike j s a o => j -> j
-- | Runs the given function if the JSON value is a number.
withNumber :: JSONLike j s a o => (Rational -> Rational) -> j -> j
-- | Runs the given function if the JSON value is a string.
withString :: JSONLike j s a o => (s -> s) -> j -> j
-- | Runs the given function if the JSON value is an array.
withArray :: JSONLike j s a o => (a j -> a j) -> j -> j
-- | Runs the given function if the JSON value is an object.
withObject :: JSONLike j s a o => (o j -> o j) -> j -> j
-- | Runs the given function on the fields if the JSON value is an object.
withObjectFields :: (Functor o, JSONLike j s a o) => (j -> j) -> j -> j
-- | The JSON value zero.
jzero :: JSONLike j s a o => j
-- | The JSON value empty string.
jemptystring :: (Monoid s, JSONLike j s a o) => j
-- | The JSON value empty array.
jemptyarray :: (Monoid (a j), JSONLike j s a o) => j
-- | The JSON value empty object.
jemptyobject :: (Monoid (o j), JSONLike j s a o) => j
-- | Puts a single value into a JSON array.
jsinglearray :: (Applicative a, JSONLike j s a o) => j -> j
-- | Puts a single value into a JSON object.
jsingleobject :: (Applicative o, JSONLike j s a o) => j -> j
-- | Returns the potential boolean value of a JSON value.
getBool :: (Failure (ExpectedBool j) m, JSONLike j s a o) => j -> m Bool
getNumber :: (Failure (ExpectedNumber j) m, JSONLike j s a o) => j -> m Rational
-- | Returns the potential string value of a JSON value.
getString :: (Failure (ExpectedString j) m, JSONLike j s a o) => j -> m s
-- | Returns the potential array value of a JSON value.
getArray :: (Failure (ExpectedArray j) m, JSONLike j s a o) => j -> m (a j)
-- | Returns the potential object value of a JSON value.
getObject :: (Failure (ExpectedObject j) m, JSONLike j s a o) => j -> m (o j)
-- | Returns whether or not a JSON is a boolean value.
isBool :: JSONLike j s a o => j -> Bool
-- | Returns whether or not a JSON is a boolean with the value true.
isTrue :: JSONLike j s a o => j -> Bool
-- | Returns whether or not a JSON is a boolean with the value false.
isFalse :: JSONLike j s a o => j -> Bool
-- | Returns whether or not a JSON is a number value.
isNumber :: JSONLike j s a o => j -> Bool
-- | Returns whether or not a JSON is a string value.
isString :: JSONLike j s a o => j -> Bool
-- | Returns whether or not a JSON is an array value.
isArray :: JSONLike j s a o => j -> Bool
-- | Returns whether or not a JSON is an object value.
isObject :: JSONLike j s a o => j -> Bool
-- | Returns a number value from a JSON value or if it is not a number,
-- returns the given default.
numberOr :: JSONLike j s a o => Rational -> j -> Rational
-- | Returns a string value from a JSON value or if it is not a string,
-- returns the given default.
stringOr :: JSONLike j s a o => s -> j -> s
-- | Returns a rational value from a JSON value or if it is not a rational,
-- returns the given default.
arrayOr :: JSONLike j s a o => a j -> j -> a j
-- | Returns an object value from a JSON value or if it is not an object,
-- returns the given default.
objectOr :: JSONLike j s a o => o j -> j -> o j
-- | Returns an object's fields from a JSON value or if it is not an
-- object, returns the given default.
fieldsOr :: JSONField j f => [f] -> j -> [f]
-- | Returns an object's values from a JSON value or if it is not an
-- object, returns the given default.
valuesOr :: JSONField j f => [j] -> j -> [j]
-- | Returns a number value from a JSON value or if it is not a number,
-- returns zero.
numberOrZero :: JSONLike j s a o => j -> Rational
-- | Returns a string value from a JSON value or if it is not a string,
-- returns an empty string.
stringOrEmpty :: (JSONLike j s a o, Monoid s) => j -> s
-- | Returns an array value from a JSON value or if it is not an array,
-- returns an empty array.
arrayOrEmpty :: (JSONLike j s a o, Monoid (a j)) => j -> a j
-- | Returns an object value from a JSON value or if it is not an object,
-- returns an empty object.
objectOrEmpty :: (JSONLike j s a o, Monoid (o j)) => j -> o j
-- | Returns an object's fields from a JSON value or if it is not an
-- object, returns no fields.
objectFieldsOrEmpty :: (JSONField j f, Monoid (o j)) => j -> [f]
-- | Returns an object's values from a JSON value or if it is not an
-- object, returns no values.
objectValuesOrEmpty :: (JSONField j f, Monoid (o j)) => j -> [j]
-- | Runs a function on the number of a JSON value or if it is not a
-- number, returns the given default.
usingNumber :: JSONLike j s a o => x -> (Rational -> x) -> j -> x
-- | Runs a function on the string of a JSON value or if it is not a
-- string, returns the given default.
usingString :: JSONLike j s a o => x -> (s -> x) -> j -> x
-- | Runs a function on the array of a JSON value or if it is not an array,
-- returns the given default.
usingArray :: JSONLike j s a o => x -> (a j -> x) -> j -> x
-- | Runs a function on the object of a JSON value or if it is not an
-- object, returns the given default.
usingObject :: JSONLike j s a o => x -> (o j -> x) -> j -> x
-- | Runs a function on the fields of an object of a JSON value or if it is
-- not an object, returns the given default.
usingObjectFields :: JSONField j f => a -> ([f] -> a) -> j -> a
-- | Runs a function on the values of an object of a JSON value or if it is
-- not an object, returns the given default.
usingObjectValues :: JSONField j f => a -> ([j] -> a) -> j -> a
-- | Whether or not a JSON value is an object with the given field.
hasField :: JSONField j f => f -> j -> Bool
-- | Whether or not a JSON value is an object with the given field. An
-- alias for hasField.
(-?) :: JSONField j f => f -> j -> Bool
-- | Returns the possible value associated with the given field if this is
-- an object. An alias for field.
(-|) :: (JSONField j f, Failure (NoSuchFieldOrExpectedObject f j) m) => f -> j -> m j
-- | Returns the value associated with the given field or if this is not an
-- object or has no associated value, return the given default.
fieldOr :: JSONField j f => f -> j -> j -> j
-- | Returns the value associated with the given field or if this is not an
-- object or has no associated value, return a JSON null.
fieldOrNull :: (JSONLike j s a o, JSONField j f) => f -> j -> j
-- | Returns the value associated with the given field or if this is not an
-- object or has no associated value, return a JSON true.
fieldOrTrue :: (JSONLike j s a o, JSONField j f) => f -> j -> j
-- | Returns the value associated with the given field or if this is not an
-- object or has no associated value, return a JSON false.
fieldOrFalse :: (JSONLike j s a o, JSONField j f) => f -> j -> j
-- | Returns the value associated with the given field or if this is not an
-- object or has no associated value, return a JSON zero.
fieldOrZero :: (JSONLike j s a o, JSONField j f) => f -> j -> j
-- | Returns the value associated with the given field or if this is not an
-- object or has no associated value, return a JSON string that is empty.
fieldOrEmptyString :: (JSONLike j s a o, JSONField j f, Monoid s) => f -> j -> j
-- | Returns the value associated with the given field or if this is not an
-- object or has no associated value, return a JSON array that is empty.
fieldOrEmptyArray :: (JSONLike j s a o, JSONField j f, Monoid (a j)) => f -> j -> j
-- | Returns the value associated with the given field or if this is not an
-- object or has no associated value, return a JSON object that is empty.
fieldOrEmptyObject :: (JSONLike j s a o, JSONField j f, Monoid (o j)) => f -> j -> j
-- | Traverses down JSON objects with the association fields and returns
-- true if the association graph exists.
hasField' :: (JSONField j f, Foldable t) => t f -> j -> Bool
-- | Traverses down JSON objects with the association fields and returns
-- true if the association graph exists. An alias for hasField'.
(-??) :: (JSONField j f, Foldable t) => t f -> j -> Bool
-- | Traverses down JSON objects with the association fields and returns
-- the potential value.
field' :: (Foldable t, Failure (NoSuchFieldOrExpectedObject f j) m, JSONField j f) => t f -> j -> m j
-- | Traverses down JSON objects with the association fields and returns
-- the potential value. An alias for field'.
(-||) :: (Foldable t, Failure (NoSuchFieldOrExpectedObject f j) m, JSONField j f) => t f -> j -> m j
-- | Traverses down JSON objects with the association fields and returns
-- the potential value or the given default.
field'Or :: (JSONField j f, Foldable t) => j -> t f -> j -> j
-- | Traverses down JSON objects with the association fields and returns
-- the potential value or a JSON null.
field'OrNull :: (JSONLike j s a o, JSONField j f, Foldable t) => t f -> j -> j
-- | Traverses down JSON objects with the association fields and returns
-- the potential value or a JSON true.
field'OrTrue :: (JSONLike j s a o, JSONField j f, Foldable t) => t f -> j -> j
-- | Traverses down JSON objects with the association fields and returns
-- the potential value or a JSON false.
field'OrFalse :: (JSONLike j s a o, JSONField j f, Foldable t) => t f -> j -> j
-- | Traverses down JSON objects with the association fields and returns
-- the potential value or a JSON zero.
field'OrZero :: (JSONLike j s a o, JSONField j f, Foldable t) => t f -> j -> j
-- | Traverses down JSON objects with the association fields and returns
-- the potential value or a JSON empty string.
field'OrEmptyString :: (JSONLike j s a o, JSONField j f, Foldable t, Monoid s) => t f -> j -> j
-- | Traverses down JSON objects with the association fields and returns
-- the potential value or a JSON empty array.
field'OrEmptyArray :: (JSONLike j s a o, JSONField j f, Foldable t, Monoid (a j)) => t f -> j -> j
-- | Traverses down JSON objects with the association fields and returns
-- the potential value or a JSON empty object.
field'OrEmptyObject :: (JSONLike j s a o, JSONField j f, Foldable t, Monoid (o j)) => t f -> j -> j
-- | Interacts by parsing the standard input for JSON, passing the result
-- to the given function, then printing the result to standard output.
interactJSON :: (JSONPrint j' s, JSONParse j s e, Interact s) => (Either e j -> j') -> IO ()
-- | Interacts by parsing the standard input for JSON, passing a failed
-- result with a string error message to the given function, or a
-- successful result to the given function, then printing the result to
-- standard output.
interactJSON' :: (JSONPrint j' s, JSONParse j s e, Interact s) => (e -> j') -> (j -> j') -> IO ()
-- | Interacts by parsing the standard input for JSON, executing the given
-- function for a failed result with a string error message, or printing
-- a successful result to the given function and passing the result to
-- standard output.
withJSON :: (Interact p, Interact s, JSONPrint j' s, JSONParse j p e) => (e -> IO ()) -> (j -> j') -> IO ()
-- | Parses a JSON file into a possible JSON object.
readJSONFile :: (JSONParse j a e, InteractFile a) => FilePath -> IO (Either e j)
-- | Writes a JSON object to a file.
writeJSONFile :: (InteractFile b, JSONPrint a b) => FilePath -> a -> IO ()
-- | Interacts by parsing the given file for JSON, passing the result to
-- the given function, then writing the result to the given file.
interactJSONFile :: (InteractFile p, InteractFile s, JSONPrint j' s, JSONParse j p e) => (Either e j -> j') -> FilePath -> FilePath -> IO ()
-- | Interacts by parsing the given file for JSON, passing a failed result
-- with a string error message to the given function, or a successful
-- result to the given function, then writing the result to the given
-- file.
interactJSONFile' :: (InteractFile p, InteractFile s, JSONPrint j' s, JSONParse j p e) => (e -> j') -> (j -> j') -> FilePath -> FilePath -> IO ()
-- | Interacts by parsing the given file for JSON, executing the given
-- function for a failed result with a string error message, or printing
-- a successful result to the given function and writing the result to
-- the given file.
withJSONFile :: (InteractFile p, InteractFile s, JSONPrint j' s, JSONParse j p e) => (e -> IO ()) -> (j -> j') -> FilePath -> FilePath -> IO ()