taon

module
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2022 License: MIT

README

taon

CI Status Go Report Card

Transform JSON into ASCII table.

Installation

taon is a stand-alone cli utility. You can just download a binary and run it.

Drop the binary in your $PATH (e.g. ~/bin) to make it easy to use.

Usage

Reading

Read a JSON array from a file:

$ taon pkg/taon/testdata/example.json
+-------+-------+--------+-----+---------------------+
| bool  | count | number | seq | word                |
+-------+-------+--------+-----+---------------------+
| false | 0001  | 779    | 1   | electrophototherapy |
| true  | 0002  | 700    | 2   | twatterlight        |
| false | 0003  | 310    | 3   | phlebograph         |
| false | 0004  | 742    | 4   | Ervipiame           |
| false | 0005  | 841    | 5   | annexational        |
| true  | 0006  | 352    | 6   | unjewel             |
| true  | 0007  | 852    | 7   | Anglic              |
| true  | 0008  | 818    | 8   | alliable            |
| true  | 0009  | 822    | 9   | seraphism           |
| true  | 0010  | 822    | 10  | congenialize        |
| false | 0011  | 549    | 11  | phu                 |
| false | 0012  | 777    | 12  | vial                |
+-------+-------+--------+-----+---------------------+

or from a cURL output:

$ curl -s https://github.com/eiri/taon/blob/main/pkg/taon/testdata/example.json | taon
+-------+-------+--------+-----+---------------------+
| bool  | count | number | seq | word                |
+-------+-------+--------+-----+---------------------+
| false | 0001  | 779    | 1   | electrophototherapy |
| true  | 0002  | 700    | 2   | twatterlight        |
| false | 0003  | 310    | 3   | phlebograph         |
| false | 0004  | 742    | 4   | Ervipiame           |
| false | 0005  | 841    | 5   | annexational        |
| true  | 0006  | 352    | 6   | unjewel             |
| true  | 0007  | 852    | 7   | Anglic              |
| true  | 0008  | 818    | 8   | alliable            |
| true  | 0009  | 822    | 9   | seraphism           |
| true  | 0010  | 822    | 10  | congenialize        |
| false | 0011  | 549    | 11  | phu                 |
| false | 0012  | 777    | 12  | vial                |
+-------+-------+--------+-----+---------------------+

Note: By default taon sorts columns alphabetically by a name to preserve order's stability. To explicitly define the order of the columns use --columns flag with comma separated list of the names

Reading JSON objects

For objects taon builds a table with keys and values columns, instead of trying to present each object's key as a column.

Rows are sorted by key or printed in the order defined with --columns flag, same as the columns when reading JSON arrays.

$ jq '.[0]' pkg/taon/testdata/example.json | taon
+--------+---------------------+
| keys   | values              |
+--------+---------------------+
| bool   | false               |
| count  | 0001                |
| number | 779                 |
| seq    | 1                   |
| word   | electrophototherapy |
+--------+---------------------+
Filtering

Filter columns to a given list in the specified order:

$ taon -c seq,word,bool pkg/taon/testdata/example.json
+-----+---------------------+-------+
| seq | word                | bool  |
+-----+---------------------+-------+
| 1   | electrophototherapy | false |
| 2   | twatterlight        | true  |
| 3   | phlebograph         | false |
| 4   | Ervipiame           | false |
| 5   | annexational        | false |
| 6   | unjewel             | true  |
| 7   | Anglic              | true  |
| 8   | alliable            | true  |
| 9   | seraphism           | true  |
| 10  | congenialize        | true  |
| 11  | phu                 | false |
| 12  | vial                | false |
+-----+---------------------+-------+

$ jq '.[0]' pkg/taon/testdata/example.json | taon -c seq,word,bool
+------+---------------------+
| keys | values              |
+------+---------------------+
| seq  | 1                   |
| word | electrophototherapy |
| bool | false               |
+------+---------------------+
Markdown

Print a table as markdown:

$ taon --columns seq,word,bool --markdown pkg/taon/testdata/example.json
| seq | word                | bool  |
|-----|---------------------|-------|
| 1   | electrophototherapy | false |
| 2   | twatterlight        | true  |
| 3   | phlebograph         | false |
| 4   | Ervipiame           | false |
| 5   | annexational        | false |
| 6   | unjewel             | true  |
| 7   | Anglic              | true  |
| 8   | alliable            | true  |
| 9   | seraphism           | true  |
| 10  | congenialize        | true  |
| 11  | phu                 | false |
| 12  | vial                | false |

$ jq '.[0]' pkg/taon/testdata/example.json | taon --columns seq,word,bool --markdown
| keys | values              |
|------|---------------------|
| seq  | 1                   |
| word | electrophototherapy |
| bool | false               |
Limitations

taon only works with objects or arrays of objects, passing in an array of arbitrary data will return an error.

Help

$ taon --help
Transform JSON into ASCII table

Usage: taon [flags] [file]

Flags:
  -c, --columns=COL1,COL2  List of columns to display
  -m, --markdown           Print as markdown table
  -h, --help               Show help
      --version            Show application version

Args:
  <file>                   Path to file to read, stdin when missing

Licence

MIT

Directories

Path Synopsis
cmd
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL