blob: c33a9b03198c1b216a7e69b64098d84e46eeafc9 [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#/usr/bin/env python
2'''
3Created on 07-Jan-2013
Jon Hall4ba53f02015-07-29 13:07:41 -07004
adminbae64d82013-08-01 10:50:15 -07005@author: Raghav Kashyap(raghavkashyap@paxterrasolutions.com)
6
7 TestON is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 2 of the License, or
10 (at your option) any later version.
11
12 TestON is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17
18 You should have received a copy of the GNU General Public License
Jon Hall4ba53f02015-07-29 13:07:41 -070019 along with TestON. If not, see <http://www.gnu.org/licenses/>.
adminbae64d82013-08-01 10:50:15 -070020
21
22'''
23
adminbae64d82013-08-01 10:50:15 -070024import json
25class JsonParser:
26 '''
Jon Hall4ba53f02015-07-29 13:07:41 -070027 Module that parses the response Json to Dictionary and Vice versa.
adminbae64d82013-08-01 10:50:15 -070028 '''
29 def __init__(self) :
30 self.default = ''
31
32 def response_parse(self,json_response):
33 '''
34 This will parse the json formatted string and return content as Dictionary
35 '''
36 response_dict = {}
37 try :
38 response_dict = json.loads(json_response)
Jon Hallfebb1c72015-03-05 13:30:09 -080039 except Exception:
adminbae64d82013-08-01 10:50:15 -070040 main.log.error("Json Parser is unable to parse the string")
Jon Hall4ba53f02015-07-29 13:07:41 -070041 return response_dict
42
adminbae64d82013-08-01 10:50:15 -070043 '''
Jon Hall4ba53f02015-07-29 13:07:41 -070044
adminbae64d82013-08-01 10:50:15 -070045 def dict_json(self,response_dict):
Jon Hall4ba53f02015-07-29 13:07:41 -070046
adminbae64d82013-08-01 10:50:15 -070047 # This will parse the Python Dictionary and return content as Json string.
Jon Hall4ba53f02015-07-29 13:07:41 -070048
adminbae64d82013-08-01 10:50:15 -070049 json_response = {}
50 try :
51 json_response = json.dumps(response_dict)
Jon Hallfebb1c72015-03-05 13:30:09 -080052 except Exception:
adminbae64d82013-08-01 10:50:15 -070053 main.log.error("Json Parser is unable to parse the string")
Jon Hall4ba53f02015-07-29 13:07:41 -070054 return json_response
adminbae64d82013-08-01 10:50:15 -070055 '''