diff --git a/htools/Ganeti/JSON.hs b/htools/Ganeti/JSON.hs index 132c0b22330845c120b6bcbadf28f32aa779aae8..7c7dd3423458dce17d1d799dad4db8e55aa085be 100644 --- a/htools/Ganeti/JSON.hs +++ b/htools/Ganeti/JSON.hs @@ -31,6 +31,7 @@ module Ganeti.JSON , fromObjWithDefault , fromKeyValue , fromJVal + , jsonHead , asJSObject , asObjectList , tryFromObj @@ -125,6 +126,11 @@ fromJVal v = "', error: " ++ s) J.Ok x -> return x +-- | Helper function that returns Null or first element of the list. +jsonHead :: (J.JSON b) => [a] -> (a -> b) -> J.JSValue +jsonHead [] _ = J.JSNull +jsonHead (x:_) f = J.showJSON $ f x + -- | Converts a JSON value into a JSON object. asJSObject :: (Monad m) => J.JSValue -> m (J.JSObject J.JSValue) asJSObject (J.JSObject a) = return a