Skip to content
/ table Public

Utility tool to print CSV or JSON documents in a table format.

License

Notifications You must be signed in to change notification settings

elwin/table

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

table

table is a utility tool to print CSV or JSON documents in a table format.

Installation

Homebrew

brew install elwin/tools/table

Snap

snap install table

Go

Requires a go toolchain installation to be present.

go get github.com/elwin/table

Usage

$ echo 'id,name,price
  1,apple,15
  2,banana,10' | table
+----+--------+-------+
| ID |  NAME  | PRICE |
+----+--------+-------+
|  1 | apple  |    15 |
|  2 | banana |    10 |
+----+--------+-------+

By default, CSV will be assumed. Alternatively, JSON can be used by specifying --format json or -f json:

$ echo '[
  {
    "id": "1",
    "name": "apple",
    "price": "15"
  },
  {
    "id": "2",
    "name": "banana",
    "price": "10"
  }
]' | table --format json
+----+--------+-------+
| ID |  NAME  | PRICE |
+----+--------+-------+
|  1 | apple  |    15 |
|  2 | banana |    10 |
+----+--------+-------+

Instead of reading from stdin we can also specify a file using -i or --input-file:

$ table --input-file testfiles/sample.csv
+----+--------+-------+
| ID |  NAME  | PRICE |
+----+--------+-------+
|  1 | apple  |    15 |
|  2 | banana |    10 |
+----+--------+-------+

Limitations

Ordering in JSON results

When using a JSON document as input, the headers are sorted alphabetically. This is due to the usage of map[string]string when un-marshalling, which otherwise gives non-deterministic results.

JSON document format

The JSON documents needs to contain a list as the top-level structure and non-nested dictionaries as elements of this list.

About

Utility tool to print CSV or JSON documents in a table format.

Resources

License

Stars

Watchers

Forks

Packages

No packages published