all2md.diff.renderers.json
JSON diff renderer for structured output.
This renderer parses unified diff format and produces machine-readable JSON output for programmatic processing.
- class all2md.diff.renderers.json.JsonDiffRenderer
Bases:
objectRender unified diff as structured JSON.
This renderer parses unified diff output and produces JSON suitable for programmatic processing, API responses, and further analysis.
- Parameters:
pretty_print (bool, default = True) – If True, format JSON with indentation
indent (int, default = 2) – Number of spaces for indentation (if pretty_print=True)
Examples
- Render diff as JSON:
>>> from all2md.diff import compare_files >>> from all2md.diff.renderers import JsonDiffRenderer >>> diff_lines = compare_files("old.docx", "new.docx") >>> renderer = JsonDiffRenderer() >>> json_output = renderer.render(diff_lines)
Initialize the JSON diff renderer.
- __init__(pretty_print: bool = True, indent: int = 2)
Initialize the JSON diff renderer.
- render(diff: DiffResult | Iterator[str]) str
Render unified diff to JSON string.
- Parameters:
diff (DiffResult or iterator of str) – Diff result or lines of unified diff output
- Returns:
JSON-formatted diff output
- Return type:
str
- all2md.diff.renderers.json.render_to_file(diff: DiffResult | Iterator[str], output_path: str, **kwargs: Any) None
Render unified diff to a JSON file.
- Parameters:
diff (DiffResult or iterator of str) – Diff payload to serialise (structured result or raw unified diff lines).
output_path (str) – Destination path for the generated JSON file.
**kwargs – Additional keyword arguments forwarded to
JsonDiffRenderer.