21 lines
588 B
Python
21 lines
588 B
Python
from os import path
|
|
import json
|
|
|
|
|
|
def read_json(filepath: str) -> dict:
|
|
if not path.exists(filepath):
|
|
raise FileNotFoundError(f"JSON file {filepath} not found!")
|
|
|
|
with open(filepath, 'r') as json_file:
|
|
data = json.load(json_file)
|
|
return data
|
|
|
|
def write_json(filepath: str, data: dict):
|
|
if not path.exists(filepath):
|
|
raise FileNotFoundError(f"JSON file {filepath} not found!")
|
|
|
|
try:
|
|
with open(filepath, 'w') as json_file:
|
|
json.dump(data, json_file, indent=4)
|
|
except Exception as e:
|
|
raise e |