-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindentacion.py
31 lines (25 loc) · 1.07 KB
/
indentacion.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
27
28
29
30
31
import json
def indent_json_file(input_file, output_file, indent=4):
"""
Lee el archivo JSON, lo parsea y escribe una versión indentada en otro archivo.
Args:
- input_file (str): Ruta al archivo JSON de entrada.
- output_file (str): Ruta al archivo JSON de salida con indentación.
- indent (int): Número de espacios para la indentación (por defecto es 4).
"""
try:
# Leer el contenido del archivo JSON
with open(input_file, 'r') as f:
data = json.load(f)
# Escribir el contenido indentado en el archivo de salida
with open(output_file, 'w') as f:
json.dump(data, f, indent=indent)
print(f"Indentación exitosa. Archivo guardado como '{output_file}'.")
except FileNotFoundError:
print(f"Error: El archivo '{input_file}' no fue encontrado.")
except json.JSONDecodeError:
print(f"Error: No se pudo decodificar el archivo '{input_file}' como JSON.")
# Uso del método
input_path = "configIA.json"
output_path = "configIA.json"
indent_json_file(input_path, output_path)