Skip to content
Data2026-08-282 min read

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:

  1. Paste the whole <table>...</table> (or a fragment containing a table);
  2. The tool parses the DOM, auto-expands merged cells, and builds an object array from headers;
  3. Preview to confirm alignment, then copy;
  4. 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.


Advertisement