From b448cc8effb69cac05495dc04acdd22c02a02bdc Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Mon, 18 Feb 2013 14:43:02 +0100 Subject: [PATCH] uri: load JSON for content-type: application/json document check prefix of content-type and merge dicts amend doc load JSON into 'json' subkey --- library/uri | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/library/uri b/library/uri index 7b0b28f6ab5..178cd6a4427 100644 --- a/library/uri +++ b/library/uri @@ -72,7 +72,7 @@ options: default: "GET" return_content: description: - - Whether or not to return the body of the request as a "content" key in the dictionary result. + - Whether or not to return the body of the request as a "content" key in the dictionary result. If the reported Content-type is "application/json", then the JSON is additionally loaded into a key called C(json) in the dictionary results. required: false choices: [ "yes", "no" ] default: no @@ -330,6 +330,14 @@ def main(): ukey = key.replace("-", "_") uresp[ukey] = value + if 'content_type' in uresp: + if uresp['content_type'].startswith('application/json'): + try: + js = json.loads(content) + uresp['json'] = js + except: + pass + if resp['status'] != status_code: module.fail_json(msg="Status code was not " + status_code, content=content, **uresp) elif return_content: