jtbl icon indicating copy to clipboard operation
jtbl copied to clipboard

Preserve field order when resizing or truncating

Open kellyjonbrazil opened this issue 2 years ago • 0 comments

In general, if jtbl is not resizing or truncating fields it will preserve the order of fields in the column output. Field order has no significance in JSON, so this is best effort. That is, there may be records that don't include all of the fields or the fields may be in a different order, so there is not an obvious way to do this.

Today, if jtbl encounters a new field that didn't exist in previous records, it will place that column at the end of the table, even when not resizing or truncating fields.

When resizing or truncating, jtbl checks all of the rows (including the header) and finds the largest cell for each column and basically truncates/resizes them and prints them out in the order of which column has the least-longest cell to the column with the largest cell.

It could be possible to scan all fields that exist in all of the records of the JSON document and try to preserve the column order in some way. It might also be possible to have built-in options to sort the columns alphabetically, by size, user-defined ordering, etc.

kellyjonbrazil avatar Sep 01 '21 18:09 kellyjonbrazil