HTML Table to JSON

Read the first HTML table into JSON or CSV. The other direction is JSON to HTML table · JSON to CSV

What this page does

An HTML table is already rows and columns. This page reads the first table into JSON or CSV. The other direction is JSON to HTML table. A JSON file that is already rows can use JSON to CSV.

How to use it

  1. Paste HTML. Update as you type is on. Output starts at JSON.
  2. Convert runs once. Show Example fills the table whose head cells are id, name and ok, with rows 1 / Ada / true and 2 / Grace / false, and sets Output to JSON.
  3. The JSON is two objects. Every value is a string: "1", "Ada", "true", then "2", "Grace", "false".
  4. Switch Output to CSV. The text is id,name,ok, then 1,Ada,true, then 2,Grace,false, with no quotes around those cells.
  5. Clear All empties both boxes. Copy Result copies the output.

Rules and edges

Only the first table is read. A head row of th cells becomes the keys. A body row with no head uses col1, col2 and so on. Tags inside a cell are dropped and the text is kept. A cell is always a string, so a number and a boolean do not come back as JSON types. A comma, a quote or a line break inside a CSV cell is quoted.

Where people use it

  • Lifting a simple HTML table into JSON.
  • Making a CSV from a table that has no quotes in the cells.
  • Checking that the reverse of the JSON table page keeps the text.

Questions

Why is id a string?

A table cell has text, not a JSON type. 1 is stored as "1".

What if the page has two tables?

The first table is the one that is read.