HTML table to JSON — the keys are only as good as the header row
The objects come out keyed by whatever the first row of markup happened to say. On a real vendor page that header may be styled, merged, or repeat a label — and each of those shapes changes the keys your code receives. This page is about key derivation, not about parsing HTML.
Cell formatting, colours, column widths and merged ranges are dropped; only stored values survive.
Processed on your device. Files aren’t sent anywhere.
Keys come from the first markup row
The reader takes the first row as the header and writes one object per following row.
- Header text becomes the property name.
- A blank header cell gets a generated name such as column_2.
- A repeated label gets a numeric suffix.
- Cells are read as text, so every value is a string.
Questions
Why are some keys called column_2?
What does a colspan header do to the keys?
Is a blank cell an empty string?
Do links and styling appear in the objects?
Merged and repeated headers
Publishers use colspan to group columns, and the grouping is where keys go wrong.
| Header row | Keys produced | Risk |
|---|---|---|
| Name, Price, Stock | name, price, stock | clean |
| Region (colspan 3), Price, Stock | region, price, stock | one label for three cells |
| Name, Name, Price | name, name_2, price | the duplicate is renamed |
| (blank), Price, Stock | column_1, price, stock | generated names |
Blank cells become null
A cell with no text becomes null, not an empty string and not zero. A price the page left blank therefore arrives as a value your code must handle explicitly.
Styling, links and scripts are dropped
Markup carries presentation and behaviour that a JSON payload has no field for. Classes, inline styles, link destinations and scripts contribute nothing; only the text of a cell is read.
A page can look informative and carry almost no data. The extraction reads text, and the rest of the markup is decoration.
Why the record count can be smaller than the page suggests
Checking the records
Validate the payload before using it.
- Convert the .html file and download the JSON.
- Parse it and list the keys you actually got.
- Look for generated names such as column_2.
- Decide how nulls should be treated.
- Compare the object count with the number of data rows on the page.