The JSON Output
The example HTML table produces this JSON:
[
{ "Name": "Alice", "Age": "30", "City": "Istanbul" },
{ "Name": "Bob", "Age": "25", "City": "Ankara" }
]
The first <tr> defines the property names. Each subsequent <tr> becomes an object in the array. Cell values are always strings since HTML has no type information.
How HTML Tables Map to JSON
HTML tables have a natural tabular structure that maps directly to an array of objects.
| HTML Element | JSON Equivalent |
|---|---|
<table> | Root array |
<tr> (first row) | Object keys |
<tr> (subsequent rows) | Array elements |
<td> / <th> | Property value |
<thead> + <tbody> | Header row + data rows |
The converter reads the first row as the schema and every following row as data. If the table uses <thead> and <tbody>, the header row comes from <thead> and data rows from <tbody>.
When to Convert HTML to JSON
Web Scraping
HTML pages display data in tables for human readability, but you need that data as structured JSON for programmatic use. Converting an HTML table to JSON gives you an array of objects you can filter, sort, and transform without parsing HTML yourself.
Data Migration
Legacy systems often export reports as HTML pages. If you need to import that data into a modern system, converting the HTML tables to JSON is faster than writing a custom parser for each legacy export format.
API Workarounds
Some websites expose data only as HTML tables, not as JSON APIs. Converting the HTML to JSON in your browser lets you extract the data without hitting the server or dealing with CORS restrictions.
Document Processing
PDFs and HTML documents contain tabular data that needs to be extracted. Converting the HTML representation to JSON gives you a clean data structure you can feed into analytics tools or databases.
Handling Edge Cases
Empty Cells
HTML tables often have empty <td></td> elements for missing data. The converter produces empty strings for these cells in the JSON output. You can post-process the JSON to replace empty strings with null if your application expects it.
Header Row Detection
The converter assumes the first row is the header. Tables that start with a title row or caption need the title removed before conversion. Tables without a clear header row get generic column names.
Multiple Tables
HTML pages often contain multiple tables. The converter processes each table separately. If you paste HTML with several tables, you get a JSON array for each one. Pick the table you need from the output.
Limitations
HTML tables are presentation, not data. The converter extracts content but loses styling, links, images, and inline formatting. If a cell contains both text and a link, you get the text content without the URL. For rich content extraction, you need a more sophisticated scraper that can parse the full DOM structure.