all2md.options.json

Options for JSON parsing and rendering.

This module defines configuration options for converting between JSON and AST. The parser converts JSON structures to readable document format, while the renderer extracts tables and structured data from documents back to JSON.

class all2md.options.json.JsonParserOptions

Bases: BaseParserOptions

Configuration options for JSON to AST parsing.

By default the parser emits the JSON as a fenced code block (literal_block). Set literal_block=False to convert JSON structures into a human-readable document instead: - Objects/dicts become heading hierarchies - Arrays of objects become tables - Arrays of primitives become lists - Nested structures become subsections

Parameters:
  • max_heading_depth (int, default = 6) – Maximum nesting depth for headings. Deeper structures will be rendered as definition lists or nested paragraphs instead of headings.

  • array_as_table_threshold (int, default = 1) – Minimum number of items in an array to render it as a table (for arrays of objects with consistent keys). Set to 2 or higher to render single-item arrays as definition lists instead of tables.

  • flatten_single_keys (bool, default = True) – If True, flatten objects that contain only a single key. For example, {“wrapper”: {“actual_data”: “value”}} becomes “# actual_data” instead of “# wrapper” > “## actual_data”.

  • include_type_hints (bool, default = False) – If True, add metadata hints about the original JSON types (useful for round-trip conversion or debugging).

  • pretty_format_numbers (bool, default = True) – If True, format large numbers with thousand separators for readability.

  • sort_keys (bool, default = False) – If True, sort object keys alphabetically when rendering.

  • literal_block (bool, default = True) – If True (the default), render JSON as a literal fenced code block, preserving the native syntax. Set to False to convert into a structured document (headings, tables for arrays of objects, lists).

literal_block: bool = True
max_heading_depth: int = 6
array_as_table_threshold: int = 1
flatten_single_keys: bool = True
include_type_hints: bool = False
pretty_format_numbers: bool = True
sort_keys: bool = False
__init__(extract_metadata: bool = False, literal_block: bool = True, max_heading_depth: int = 6, array_as_table_threshold: int = 1, flatten_single_keys: bool = True, include_type_hints: bool = False, pretty_format_numbers: bool = True, sort_keys: bool = False) None
class all2md.options.json.JsonRendererOptions

Bases: BaseRendererOptions

Configuration options for AST to JSON rendering.

The renderer extracts structured data from markdown documents, primarily focusing on tables but optionally including lists and other elements.

Parameters:
  • extract_mode (Literal["tables", "lists", "both"], default = "tables") – What to extract from the document: - “tables”: Extract only tables as arrays of objects - “lists”: Extract only lists as arrays - “both”: Extract both tables and lists

  • type_inference (bool, default = True) – If True, automatically detect and convert types (numbers, booleans, null). If False, all values remain as strings.

  • table_heading_keys (bool, default = True) – If True, use the preceding heading text as the key name for each table. If False, tables are stored in a flat array.

  • flatten_single_table (bool, default = False) – If True and only one table is found, return the array directly instead of wrapping it in an object with a key.

  • include_table_metadata (bool, default = False) – If True, include metadata about table position, source heading, etc.

  • indent (int | None, default = 2) – Number of spaces for JSON indentation. None for compact output.

  • ensure_ascii (bool, default = False) – If True, escape non-ASCII characters in output.

  • sort_keys (bool, default = False) – If True, sort keys in output JSON.

extract_mode: Literal['tables', 'lists', 'both'] = 'tables'
type_inference: bool = True
table_heading_keys: bool = True
flatten_single_table: bool = False
include_table_metadata: bool = False
indent: int | None = 2
ensure_ascii: bool = False
sort_keys: bool = False
__init__(fail_on_resource_errors: bool = False, max_asset_size_bytes: int = 52428800, metadata_policy: MetadataRenderPolicy = <factory>, creator: str | None = 'all2md', extract_mode: Literal['tables', 'lists', 'both']='tables', type_inference: bool = True, table_heading_keys: bool = True, flatten_single_table: bool = False, include_table_metadata: bool = False, indent: int | None = 2, ensure_ascii: bool = False, sort_keys: bool = False) None