import json
import os
import tempfile
from pathlib import Path
from typing import Any
def load_json(path: str | Path) -> Any:
return json.loads(Path(path).read_text(encoding="utf-8"))
def save_json(path: str | Path, data: Any, *, indent: int = 2) -> None:
path = Path(path)
path.parent.mkdir(parents=True, exist_ok=True)
fd, tmp = tempfile.mkstemp(dir=str(path.parent), prefix=f".{path.name}-")
try:
with os.fdopen(fd, "w", encoding="utf-8") as f:
json.dump(data, f, indent=indent, ensure_ascii=False, sort_keys=True)
f.write("\n")
os.replace(tmp, path)
except BaseException:
os.unlink(tmp); raise
state = load_json("config.json")
state["last_run"] = "2025-03-12T14:00:00Z"
save_json("config.json", state)
Create a free account and build your private vault. Share publicly whenever you want.