-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_data.py
More file actions
22 lines (19 loc) · 745 Bytes
/
Copy pathjson_data.py
File metadata and controls
22 lines (19 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import json
def get_json_data(filepath):
try:
with open(filepath) as file:
json_data = file.read()
json_data = json.loads(json_data)
return json_data
except UnicodeDecodeError:
print("Trying to read this file caused a UnicodeDecodeError, is", filepath, "the correct file?")
return ""
except json.JSONDecodeError:
print("Trying to read this file caused a JSONDecodeError, is", filepath, "the correct file?")
return ""
except ValueError:
print("Trying to read this file caused an unknown error, is", filepath, "the correct file?")
return ""
def contains_key(object, key):
key = key
return str(object).find(key) != -1