-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonAPI.py
42 lines (30 loc) · 1.11 KB
/
jsonAPI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os.path
import json
import fileinput
class JSON_Tools():
def dump_Data_To_File(self, json_file_path, **kwargs):
# Converts a Python dictionary to JSON formatted data and writes it to file
all_dicts = {}
if kwargs != None:
for key, value in kwargs.items():
all_dicts[key] = value
with open(json_file_path, 'w') as outfile:
json.dump(all_dicts, outfile)
outfile.close()
def dump_Data_To_string(self, **kwargs):
# Converts a Python dictionary to JSON formatted data and writes it to file
all_dicts = {}
if kwargs != None:
for key, value in kwargs.items():
all_dicts[key] = value
return json.dumps(all_dicts)
# with open(json_file_path, 'w') as outfile:
# json.dump(all_dicts, outfile)
# outfile.close()
def Load_Data(self, json_file_path):
# Converts a JSON formatted file to Python data structure
with open(json_file_path) as json_data:
return json.load(json_data)
def Load_Data_From_String(self, json_string):
# Converts a JSON string to Python data structure
return json.loads(json_string)