2025-07-10 13:33:56 +02:00
|
|
|
import json
|
|
|
|
|
import os
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
def export_switch_to_json(switch_obj, output_path: Path):
|
|
|
|
|
def compact(obj):
|
|
|
|
|
# sérialise en JSON sans indent, puis ré-indente les lignes manuellement
|
|
|
|
|
return json.dumps(
|
|
|
|
|
obj,
|
|
|
|
|
indent=None,
|
|
|
|
|
separators=(",", ": "),
|
|
|
|
|
ensure_ascii=False
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
|
|
|
|
with open(output_path, "w", encoding="utf-8") as f:
|
|
|
|
|
parsed = json.loads(compact(switch_obj.to_dict()))
|
|
|
|
|
json.dump(parsed, f, indent=2, separators=(",", ": "), ensure_ascii=False)
|