, fromJVal
, asJSObject
, asObjectList
+ , tryFromObj
)
where
import qualified Text.JSON as J
+import Ganeti.BasicTypes
+
-- * JSON-related functions
-- | A type alias for the list-based representation of J.JSObject.
-- | Coneverts a list of JSON values into a list of JSON objects.
asObjectList :: (Monad m) => [J.JSValue] -> m [J.JSObject J.JSValue]
asObjectList = mapM asJSObject
+
+-- | Try to extract a key from a object with better error reporting
+-- than fromObj.
+tryFromObj :: (J.JSON a) =>
+ String -- ^ Textual "owner" in error messages
+ -> JSRecord -- ^ The object array
+ -> String -- ^ The desired key from the object
+ -> Result a
+tryFromObj t o = annotateResult t . fromObj o