Skip to converter

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.

Drop files here or HTML, up to 12 MB
    Add a file to start.

    Processed on your device. Files aren’t sent anywhere.

    No sign-up. Nothing to install.

    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?
    A blank header cell has no text to use as a name, so a generated name is assigned and the value is not lost.
    What does a colspan header do to the keys?
    A merged header supplies fewer labels than the data rows have cells. Extra columns get generated names, and the grouping itself is not recorded.
    Is a blank cell an empty string?
    No. It becomes null, so your code has to handle it rather than treating it as a value.
    Do links and styling appear in the objects?
    No. Only cell text is read; destinations, classes and styles are dropped.

    Merged and repeated headers

    Publishers use colspan to group columns, and the grouping is where keys go wrong.

    Header rowKeys producedRisk
    Name, Price, Stockname, price, stockclean
    Region (colspan 3), Price, Stockregion, price, stockone label for three cells
    Name, Name, Pricename, name_2, pricethe duplicate is renamed
    (blank), Price, Stockcolumn_1, price, stockgenerated 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.

    1. Convert the .html file and download the JSON.
    2. Parse it and list the keys you actually got.
    3. Look for generated names such as column_2.
    4. Decide how nulls should be treated.
    5. Compare the object count with the number of data rows on the page.

    Share this converter

    More sharing options