blob: fea797a93600b228b4f94e5c99462322d7b7cfa0 [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#/usr/bin/env python
2'''
3Created on 07-Jan-2013
4
5@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
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20
21
22'''
23
adminbae64d82013-08-01 10:50:15 -070024import json
25class JsonParser:
26 '''
27 Module that parses the response Json to Dictionary and Vice versa.
28 '''
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")
41 return response_dict
42
43 '''
44
45 def dict_json(self,response_dict):
46
47 # This will parse the Python Dictionary and return content as Json string.
48
49 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")
54 return json_response
55 '''