Metadata-Version: 2.4
Name: html-table-to-json-extractor
Version: 0.1.0
Summary: Extract HTML tables as clean JSON records
Author-email: Anonymous Developer <anonymous@example.com>
License: MIT
Project-URL: Homepage, https://apify.com/Redbaron/html-table-to-json-extractor
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# HTML Table to JSON Extractor

> **Run it hosted, no setup:** [HTML Table to JSON Extractor on Apify](https://apify.com/Redbaron/html-table-to-json-extractor) — pay per result, nothing to install or maintain.

Extract data tables from HTML pages as clean JSON records. Each table row becomes a dictionary with keys from header cells, along with metadata about the source table.

## Installation

```bash
pip install html-table-to-json-extractor-0.1.0-py3-none-any.whl
```

## Quickstart

```python
from html_table_to_json_extractor import process

html = """
<table>
    <tr><th>Product</th><th>Price</th></tr>
    <tr><td>Widget</td><td>$10</td></tr>
    <tr><td>Gadget</td><td>$20</td></tr>
</table>
"""

records = process(html, "http://example.com/products")
for record in records:
    print(record)
```

## API Reference

### `process(html: str, url: str) -> list[dict]`

Extract all HTML tables from the given HTML string as JSON-serializable records.

**Parameters:**
- `html`: The HTML content to parse
- `url`: The URL where the HTML was fetched from (used for context)

**Returns:**
List of dictionaries, where each dictionary represents a table row with keys from header cells. Each record includes:
- `table_index`: 0-based index of the table in the document
- `table_caption`: The table's caption if present
- Additional keys from header cells (converted to snake_case)

## Features
- Handles malformed HTML gracefully
- Properly processes nested elements in table cells
- Converts header text to snake_case for consistent keys
- Preserves table metadata (index, caption)
- No external dependencies (pure Python standard library)
