Safe Haskell | Safe-Infered |
---|
JSON utility functions.
- type JSField = (String, JSValue)
- type JSRecord = [JSField]
- fromJResult :: Monad m => String -> Result a -> m a
- fromJResultE :: (Error e, MonadError e m) => String -> Result a -> m a
- readEitherString :: Monad m => JSValue -> m String
- loadJSArray :: Monad m => String -> String -> m [JSObject JSValue]
- buildNoKeyError :: JSRecord -> String -> String
- fromObj :: (JSON a, Monad m) => JSRecord -> String -> m a
- maybeFromObj :: (JSON a, Monad m) => JSRecord -> String -> m (Maybe a)
- fromObjWithDefault :: (JSON a, Monad m) => JSRecord -> String -> a -> m a
- arrayMaybeFromJVal :: (JSON a, Monad m) => JSValue -> m [Maybe a]
- arrayMaybeFromObj :: (JSON a, Monad m) => JSRecord -> String -> m [Maybe a]
- tryArrayMaybeFromObj :: JSON a => String -> JSRecord -> String -> Result [Maybe a]
- fromKeyValue :: (JSON a, Monad m) => String -> JSValue -> m a
- fromJVal :: (Monad m, JSON a) => JSValue -> m a
- fromJValE :: (Error e, MonadError e m, JSON a) => JSValue -> m a
- jsonHead :: JSON b => [a] -> (a -> b) -> JSValue
- getMaybeJsonHead :: JSON b => [a] -> (a -> Maybe b) -> JSValue
- getMaybeJsonElem :: JSON b => [a] -> Int -> (a -> Maybe b) -> JSValue
- asJSObject :: Monad m => JSValue -> m (JSObject JSValue)
- asObjectList :: Monad m => [JSValue] -> m [JSObject JSValue]
- tryFromObj :: JSON a => String -> JSRecord -> String -> Result a
- toArray :: Monad m => JSValue -> m [JSValue]
- optionalJSField :: JSON a => String -> Maybe a -> Maybe JSField
- optFieldsToObj :: [Maybe JSField] -> JSValue
- class HasStringRepr a where
- fromStringRepr :: Monad m => String -> m a
- toStringRepr :: a -> String
- newtype GenericContainer a b = GenericContainer {
- fromContainer :: Map a b
- type Container = GenericContainer String
- readContainer :: (Monad m, HasStringRepr a, Ord a, JSON b) => JSObject JSValue -> m (GenericContainer a b)
- showContainer :: (HasStringRepr a, JSON b) => GenericContainer a b -> JSValue
- newtype MaybeForJSON a = MaybeForJSON {
- unMaybeForJSON :: Maybe a
JSON-related functions
fromJResult :: Monad m => String -> Result a -> m aSource
Converts a JSON Result into a monadic value.
fromJResultE :: (Error e, MonadError e m) => String -> Result a -> m aSource
Converts a JSON Result into a MonadError value.
readEitherString :: Monad m => JSValue -> m StringSource
Tries to read a string from a JSON value.
In case the value was not a string, we fail the read (in the context of the current monad.
:: Monad m | |
=> String | Operation description (for error reporting) |
-> String | Input message |
-> m [JSObject JSValue] |
Converts a JSON message into an array of JSON objects.
buildNoKeyError :: JSRecord -> String -> StringSource
fromObj :: (JSON a, Monad m) => JSRecord -> String -> m aSource
Reads the value of a key in a JSON object.
maybeFromObj :: (JSON a, Monad m) => JSRecord -> String -> m (Maybe a)Source
Reads the value of an optional key in a JSON object. Missing
keys, or keys that have a 'null' value, will be returned as
Nothing
, otherwise we attempt deserialisation and return a Just
value.
fromObjWithDefault :: (JSON a, Monad m) => JSRecord -> String -> a -> m aSource
Reads the value of a key in a JSON object with a default if missing. Note that both missing keys and keys with value 'null' will cause the default value to be returned.
arrayMaybeFromJVal :: (JSON a, Monad m) => JSValue -> m [Maybe a]Source
arrayMaybeFromObj :: (JSON a, Monad m) => JSRecord -> String -> m [Maybe a]Source
:: JSON a | |
=> String | Textual owner in error messages |
-> JSRecord | The object array |
-> String | The desired key from the object |
-> Result [Maybe a] |
Wrapper for arrayMaybeFromObj with better diagnostic
:: (JSON a, Monad m) | |
=> String | The key name |
-> JSValue | The value to read |
-> m a |
Reads a JValue, that originated from an object key.
fromJValE :: (Error e, MonadError e m, JSON a) => JSValue -> m aSource
Small wrapper over readJSON
for MonadError
.
jsonHead :: JSON b => [a] -> (a -> b) -> JSValueSource
Helper function that returns Null or first element of the list.
getMaybeJsonHead :: JSON b => [a] -> (a -> Maybe b) -> JSValueSource
Helper for extracting Maybe values from a possibly empty list.
getMaybeJsonElem :: JSON b => [a] -> Int -> (a -> Maybe b) -> JSValueSource
Helper for extracting Maybe values from a list that might be too short.
asJSObject :: Monad m => JSValue -> m (JSObject JSValue)Source
Converts a JSON value into a JSON object.
asObjectList :: Monad m => [JSValue] -> m [JSObject JSValue]Source
Coneverts a list of JSON values into a list of JSON objects.
:: JSON a | |
=> String | Textual owner in error messages |
-> JSRecord | The object array |
-> String | The desired key from the object |
-> Result a |
Try to extract a key from an object with better error reporting than fromObj.
optionalJSField :: JSON a => String -> Maybe a -> Maybe JSFieldSource
Creates a Maybe JSField. If the value string is Nothing, the JSField will be Nothing as well.
optFieldsToObj :: [Maybe JSField] -> JSValueSource
Creates an object with all the non-Nothing fields of the given list.
Container type (special type for JSON serialisation)
class HasStringRepr a whereSource
Class of types that can be converted from Strings. This is
similar to the Read
class, but it's using a different
serialisation format, so we have to define a separate class. Mostly
useful for custom key types in JSON dictionaries, which have to be
backed by strings.
fromStringRepr :: Monad m => String -> m aSource
toStringRepr :: a -> StringSource
HasStringRepr String | Trivial instance |
HasStringRepr DiskTemplate | |
HasStringRepr Hypervisor |
newtype GenericContainer a b Source
The container type, a wrapper over Data.Map
GenericContainer | |
|
Arbitrary OsParams | |
Arbitrary IAllocatorParams | |
Arbitrary ClusterNicParams | |
Arbitrary ClusterOsParams | |
Arbitrary ClusterBeParams | |
Arbitrary OsHvParams | No real arbitrary instance for |
Arbitrary ClusterHvParams | No real arbitrary instance for |
(Eq a, Eq b) => Eq (GenericContainer a b) | |
(Show a, Show b) => Show (GenericContainer a b) | |
(NFData a, NFData b) => NFData (GenericContainer a b) | |
(HasStringRepr a, Ord a, JSON b) => JSON (GenericContainer a b) |
type Container = GenericContainer StringSource
Type alias for string keys.
readContainer :: (Monad m, HasStringRepr a, Ord a, JSON b) => JSObject JSValue -> m (GenericContainer a b)Source
showContainer :: (HasStringRepr a, JSON b) => GenericContainer a b -> JSValueSource
newtype MaybeForJSON a Source
A Maybe newtype that allows for serialization more appropriate to the semantics of Maybe and JSON in our calls. Does not produce needless and confusing dictionaries.
MaybeForJSON | |
|
JSON a => JSON (MaybeForJSON a) |