JSON Export

JSON export preserves the structured AST shape for downstream processing. It can include optional fields and image payloads based on JsonOptions.

from rtfstruct import JsonOptions, parse_rtf

document = parse_rtf(r"{\rtf1\ansi Hello}")
data = document.to_json(options=JsonOptions(include_nulls=False))
class rtfstruct.JsonOptions(include_nulls=False, include_diagnostics=True, include_image_data=False)[source]

JSON export configuration.

Parameters:
  • include_nulls (bool)

  • include_diagnostics (bool)

  • include_image_data (bool)

JSON exporter for the document AST.

The exporter consumes AST nodes only. It does not inspect RTF source text or perform parser recovery.

class rtfstruct.json_export.JsonExporter(options=None)[source]

Export a Document to deterministic JSON-compatible dictionaries.

Parameters:

options (JsonOptions | None)

export(document)[source]

Export document to JSON-compatible data.

Parameters:

document (Document)

Return type:

dict[str, object]