Last active
May 14, 2021 20:23
-
-
Save havron/c5c60fd719807fb65773f63676cb45b3 to your computer and use it in GitHub Desktop.
Python function to load JSON easily
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
def json_load(path: str) -> dict: | |
if not path: | |
return {} | |
try: | |
with open(path, 'r') as p: | |
return json.load(p) # expect dict | |
except (FileNotFoundError, json.decoder.JSONDecodeError) as e: | |
print(f"[WARNING] No recipients discovered. Reason: {e}") | |
return {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment