-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathformat_code_model.py
More file actions
26 lines (22 loc) · 905 Bytes
/
format_code_model.py
File metadata and controls
26 lines (22 loc) · 905 Bytes
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 os
import json
def format_json_file(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
try:
json_content = json.load(file)
formatted_content = json.dumps(json_content, indent=2)
with open(file_path, 'w', encoding='utf-8') as output_file:
output_file.write(formatted_content)
print(f"Formatted: {file_path}")
except json.JSONDecodeError as e:
print(f"Error decoding JSON in {file_path}: {e}")
def format_acm_files(directory):
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith('.acm'):
file_path = os.path.join(root, file)
format_json_file(file_path)
# Use the current directory
directory_path = '.'
# Call the function to format .acm files in the current directory
format_acm_files(directory_path)