Added json utils to save and load json files

This commit is contained in:
Christian Risi
2025-10-01 12:20:59 +02:00
parent 97bac464f3
commit dbf1d99408
2 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
import json
from pathlib import Path
def save_json(vocabulary: dict, path: Path):
json_string = json.dumps(vocabulary)
FILE = open(path, "w")
FILE.write(json_string)
FILE.close()
def load_json(path: Path) -> dict[tuple[int, int], int]:
FILE = open(path, "r")
json_string = FILE.read()
FILE.close()
return json.loads(json_string)