[Pkg-ganeti-devel] [ganeti] 56/165: Add a function to parse a JSON-map

Apollon Oikonomopoulos apoikos at moszumanska.debian.org
Tue Aug 11 13:53:13 UTC 2015


This is an automated email from the git hooks/post-receive script.

apoikos pushed a commit to branch master
in repository ganeti.

commit 2e15c4e3d1ce185e727c1f42ec6f8e8112648101
Author: Klaus Aehlig <aehlig at google.com>
Date:   Mon Feb 23 13:49:04 2015 +0100

    Add a function to parse a JSON-map
    
    To simplify sending data over the wire, add a function
    that tries to parse a map that is encoded as a JSON object
    in the obvious way.
    
    Signed-off-by: Klaus Aehlig <aehlig at google.com>
    Reviewed-by: Petr Pudlak <pudlak at google.com>
---
 src/Ganeti/JSON.hs | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/Ganeti/JSON.hs b/src/Ganeti/JSON.hs
index 18fddb4..e1c91b3 100644
--- a/src/Ganeti/JSON.hs
+++ b/src/Ganeti/JSON.hs
@@ -79,6 +79,7 @@ module Ganeti.JSON
   , nestedAccessByKeyDotted
   , branchOnField
   , addField
+  , maybeParseMap
   )
   where
 
@@ -537,3 +538,7 @@ branchOnField k _ _ _ = J.Error $ "Need an object to branch on key " ++ k
 addField :: (String, J.JSValue) -> J.JSValue -> J.JSValue
 addField (n,v) (J.JSObject obj) = J.JSObject $ JT.set_field obj n v
 addField _ jsval = jsval
+
+-- | Maybe obtain a map from a JSON object.
+maybeParseMap :: J.JSON a => J.JSValue -> Maybe (Map.Map String a)
+maybeParseMap = liftM fromContainer . readContainer <=< asJSObject

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ganeti/ganeti.git



More information about the Pkg-ganeti-devel mailing list