13 lines
379 B
Python
13 lines
379 B
Python
from __future__ import annotations
|
|
import json, os
|
|
|
|
def read_json(path: str):
|
|
with open(path, encoding="utf-8") as f:
|
|
return json.load(f)
|
|
|
|
def write_json(path: str, obj) -> None:
|
|
os.makedirs(os.path.dirname(path) or ".", exist_ok=True)
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
json.dump(obj, f, indent=2, ensure_ascii=False)
|
|
f.write("\n")
|