Symptom: you pasted a <table> and want JSON
You copied an HTML table from a web page, a backend export, or an email, and want JSON for programmatic use. Doing "one object per row" breaks on multi-row headers and merged cells. Here's the correct approach.
Basic idea: headers as keys, rows as objects
For a clean table (first row header, each following row a record), the logic is simple:
| Name | Age |
| Tom | 28 |
| Lily | 31 |
→
[
{ "Name": "Tom", "Age": "28" },
{ "Name": "Lily", "Age": "31" }
]
Note: table cells are strings by default; numbers and dates need later type conversion.
Common pitfalls
1. Headers spanning columns (colspan) / rows (rowspan)
A merged cell means "this cell belongs to multiple logical positions". Naive "take by column index" misaligns. Handle by:
- Expand
colspan: copy the content into each column it spans; - Expand
rowspan: fill the content down into each row it spans; - Then read the expanded full matrix.
2. Multi-level headers / nested thead
Some tables have two header rows; decide which becomes the key, or concatenate both as level1.level2.
3. Tags inside cells
If <td> wraps <a>, <span>, do you want the text or an attribute (like href)? Decide upfront.
How to convert with a tool
Open the HTML Table to JSON tool on ToolVault:
- Paste the whole
<table>...</table>(or a fragment containing a table); - The tool parses the DOM, auto-expands merged cells, and builds an object array from headers;
- Preview to confirm alignment, then copy;
- To turn it into docs, pair with HTML to Markdown.
FAQ
Are merged cells auto-expanded?
A good tool does. The key is flattening rowspan/colspan into a complete matrix before mapping keys, or later values shift.
Output numbers are all strings — does it matter?
Fine for display/storage; if they feed calculation, Number() them in code, and clean thousand-separators / currency symbols first.
Can a header-less table be converted?
Yes — the tool usually auto-numbers keys as col1, col2…; you can rename later.
Provided by ToolVault. Related tools: HTML Table to JSON, HTML to Markdown, JSON Formatter. Visit the home page for more developer tools.
Related Tools
Related Articles
Excel to JSON: Dates Become Numbers / Chinese Garbled — Fix
When converting Excel to JSON, dates turn into numbers like 44927, Chinese is garbled, empty cells vanish? Explains Excel serial dates and encoding pitfalls, with our Excel to JSON tool.
The Complete Guide to Table Format Conversion: Excel, CSV, JSON, Markdown, and HTML
A full walkthrough of converting between Excel, CSV, JSON, Markdown, and HTML tables: format characteristics, conversion paths, hands-on workflows, and common pitfalls — 12 free online converters in one place.
Online XML/JSON Converter: Convert Between Data Formats
Learn how to convert between XML and JSON formats. Understand the differences between XML and JSON, and use cases in API integration, configuration management, and data exchange.