0.1
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user