File size: 495 Bytes
7e9ce74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""Utilities."""
import json
import os
from typing import List, Dict, Any


def ensure_dir(path: str):
    os.makedirs(path, exist_ok=True)


def save_jsonl(path: str, records: List[Dict[str, Any]]):
    with open(path, "w") as f:
        for r in records:
            f.write(json.dumps(r) + "\n")


def save_json(path: str, data: Any):
    with open(path, "w") as f:
        json.dump(data, f, indent=2)


def load_json(path: str) -> Any:
    with open(path) as f:
        return json.load(f)