Documentation
¶
Overview ¶
Command tablejson converts each table in a document to JSON, one object per row, keyed by the header cells.
Reading the grid is the same work as examples/gip/tablecsv - implied end tags for cells and rows, a grid rather than a list of rows so colspan and rowspan line up, and cell content taken from cells so that content a parser fosters out of the table does not become data. What is new is that JSON needs *names*, and a table is not obliged to provide usable ones.
Which row is the header is a guess, and the program says which guess it made: the last row of a <thead> if there is one, otherwise the first row if every cell in it is a <th>, otherwise none - and with no header there are no keys, so the rows come out as arrays instead of objects. Inventing "column 1" for a table that has no header would produce JSON that looks authoritative and says nothing.
Names collide, and that is the part worth writing carefully. A header cell with colspan=2 gives two columns the same name. Two <th> can hold the same text. An empty <th> gives no name at all. JSON has no answer for a duplicate key - one of them wins, silently, and which one depends on the reader - so the program makes the keys unique, keeps the original name in the report, and counts what it had to rename. A caller can then decide whether the table was worth reading.