Skip to content

Instantly share code, notes, and snippets.

@havron
Last active May 14, 2021 20:23
Show Gist options
  • Save havron/c5c60fd719807fb65773f63676cb45b3 to your computer and use it in GitHub Desktop.
Save havron/c5c60fd719807fb65773f63676cb45b3 to your computer and use it in GitHub Desktop.
Python function to load JSON easily
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