Add formatters module
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled

This commit is contained in:
2026-01-29 13:24:04 +00:00
parent 59d4410f4c
commit a0f6701060

View File

@@ -0,0 +1,23 @@
"""JSON formatter for structured output."""
import json
from pathlib import Path
from typing import Any
class JSONFormatter:
"""Formats context data as JSON."""
def __init__(self, output_path: Path | None = None):
self.output_path = output_path
def format(self, data: dict[str, Any]) -> str:
"""Format data as JSON string."""
return json.dumps(data, indent=2, ensure_ascii=False)
def save(self, data: dict[str, Any]) -> None:
"""Save formatted data to file."""
if self.output_path:
self.output_path.parent.mkdir(parents=True, exist_ok=True)
content = self.format(data)
self.output_path.write_text(content, encoding="utf-8")