-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsplit.py
26 lines (21 loc) · 903 Bytes
/
split.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
import os
def split_json_namespaces(input_file):
with open(input_file, 'r') as file:
data = json.load(file)
output_dir = 'namespaces'
os.makedirs(output_dir, exist_ok=True)
for namespace, content in data.items():
namespace_dir = os.path.join(output_dir, namespace)
os.makedirs(namespace_dir, exist_ok=True)
for key, key_content in content.items():
if 'name' in key_content:
file_name = f"{key_content['name']}.json"
else:
file_name = f"{key}.json"
output_file = os.path.join(namespace_dir, file_name)
with open(output_file, 'w') as outfile:
json.dump({key: key_content}, outfile, indent=4)
print(f'Written key {key} of namespace {namespace} to {output_file}')
input_file = 'natives.json'
split_json_namespaces(input_file)