-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathndjson2json.py
26 lines (20 loc) · 1005 Bytes
/
ndjson2json.py
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
26
import json
from pathlib import Path
from ndjsonlib.ndjson_data_file import NdjsonDataFile
def convert_ndjson_2_json(dataset_name, standard, json_filename):
ndjson_path = Path.cwd() / "data" / "ndjson" / f"{standard}-ndjson"
ndj = NdjsonDataFile(ds_name=dataset_name, directory=ndjson_path)
ndj.read_dataset()
ndj.write_dataset_json(json_filename)
def convert_example_datasets(datasets, standard):
for dataset in datasets:
json_filename = Path.cwd() / "data" / "json" / f"{standard}-json" / f"{dataset}.json"
json_filename.parent.mkdir(parents=True, exist_ok=True)
convert_ndjson_2_json(dataset, standard, json_filename)
if __name__ == '__main__':
datalist_file_path = Path.cwd() / "data" / "dataset-list.json"
with open(datalist_file_path) as f:
ds_lists = json.load(f)
for standard, datasets in ds_lists.items():
convert_example_datasets(datasets, standard)
print(f"Successfully Converted NDJSON datasets to JSON format")