{"id":13602822,"url":"https://github.com/kellyjonbrazil/jtbl","last_synced_at":"2025-04-04T09:08:22.994Z","repository":{"id":60877166,"uuid":"245224093","full_name":"kellyjonbrazil/jtbl","owner":"kellyjonbrazil","description":"CLI tool to convert JSON and JSON Lines to terminal, CSV, HTTP, and markdown tables","archived":false,"fork":false,"pushed_at":"2024-04-02T14:23:15.000Z","size":129,"stargazers_count":302,"open_issues_count":1,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-28T08:05:38.171Z","etag":null,"topics":["bash","cli","command-line","command-line-tool","csv","json","json-lines","layout","markdown","scripting","shell-scripting","tables","terminal"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kellyjonbrazil.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-03-05T17:17:39.000Z","updated_at":"2025-03-22T10:37:24.000Z","dependencies_parsed_at":"2024-01-26T10:34:53.137Z","dependency_job_id":"b099088f-48ed-47d0-8741-57e29f97a746","html_url":"https://github.com/kellyjonbrazil/jtbl","commit_stats":{"total_commits":153,"total_committers":1,"mean_commits":153.0,"dds":0.0,"last_synced_commit":"2e4ba81ad725af8689c69d266c55c58642495889"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kellyjonbrazil%2Fjtbl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kellyjonbrazil%2Fjtbl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kellyjonbrazil%2Fjtbl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kellyjonbrazil%2Fjtbl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kellyjonbrazil","download_url":"https://codeload.github.com/kellyjonbrazil/jtbl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247149501,"owners_count":20891954,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","cli","command-line","command-line-tool","csv","json","json-lines","layout","markdown","scripting","shell-scripting","tables","terminal"],"created_at":"2024-08-01T18:01:39.070Z","updated_at":"2025-04-04T09:08:22.976Z","avatar_url":"https://github.com/kellyjonbrazil.png","language":"Python","funding_links":[],"categories":["Python","cli","\u003ca name=\"data-management-json\"\u003e\u003c/a\u003eData management - JSON/YAML/etc."],"sub_categories":[],"readme":"[![Tests](https://github.com/kellyjonbrazil/jtbl/workflows/Tests/badge.svg?branch=master)](https://github.com/kellyjonbrazil/jtbl/actions)\n[![Pypi](https://img.shields.io/pypi/v/jtbl.svg)](https://pypi.org/project/jtbl/)\n\n# jtbl\nA simple cli tool to print JSON data as a table in the terminal.\n\n`jtbl` accepts piped JSON data from `stdin` and outputs a text table representation to `stdout`. e.g:\n```\n$ cat cities.json | jtbl\n  LatD    LatM    LatS  NS      LonD    LonM    LonS  EW    City               State\n------  ------  ------  ----  ------  ------  ------  ----  -----------------  -------\n    41       5      59  N         80      39       0  W     Youngstown         OH\n    42      52      48  N         97      23      23  W     Yankton            SD\n    46      35      59  N        120      30      36  W     Yakima             WA\n    42      16      12  N         71      48       0  W     Worcester          MA\n    43      37      48  N         89      46      11  W     Wisconsin Dells    WI\n    36       5      59  N         80      15       0  W     Winston-Salem      NC\n    49      52      48  N         97       9       0  W     Winnipeg           MB\n```\n\n`jtbl` expects a JSON array of JSON objects or [JSON Lines](http://jsonlines.org/).\n\nIt can be useful to JSONify command line output with `jc`, filter through a tool like `jq`, and present in `jtbl`:\n```\n$ jc ifconfig | jq -c '.[] | {name, type, ipv4_addr, ipv4_mask}'| jtbl\nname     type            ipv4_addr       ipv4_mask\n-------  --------------  --------------  -------------\ndocker0  Ethernet        172.17.0.1      255.255.0.0\nens33    Ethernet        192.168.71.146  255.255.255.0\nlo       Local Loopback  127.0.0.1       255.0.0.0\n```\n\n## Installation\nYou can install `jtbl` via `pip`, via OS Package Repositories, MSI installer for Windows, or by downloading the correct binary for your architecture and running it anywhere on your filesystem.\n\n### Pip (macOS, linux, unix, Windows)\nFor the most up-to-date version and the most cross-platform option, use `pip` or `pip3` to download and install `jtbl` directly from [PyPi](https://pypi.org/project/jtbl/):\n\n[![Pypi](https://img.shields.io/pypi/v/jtbl.svg)](https://pypi.org/project/jtbl/)\n```bash\npip3 install jtbl\n```\n\n### OS Packages\n\n[![Packaging status](https://repology.org/badge/vertical-allrepos/jtbl.svg)](https://repology.org/project/jtbl/versions)\n\nSee [Releases](https://github.com/kellyjonbrazil/jtbl/releases) on Github for MSI packages and binaries.\n\n## Usage\nJust pipe JSON data to `jtbl`. (e.g. `cat` a JSON file, `jc`, `jq`, `aws` cli, `kubectl`, etc.)\n```\n$ \u003cJSON Data\u003e | jtbl [OPTIONS]\n```\n### Options\n- `--cols=n` manually configure the terminal width\n- `-c`, `--csv` CSV table output\n- `-d`, `--dokuwiki` Dokuwiki table output\n- `-f`, `--fancy` fancy table output\n- `-h`, `--help` prints help information\n- `-H`, `--html` HTML table output\n- `-m`, `--markdown` markdown table output\n- `-n`, `--no-wrap` no data wrapping if too long for the terminal width (overrides `--cols` and `-t`)\n- `-q`, `--quiet` don't print error messages to STDERR\n- `-r`, `--rotate` rotate the data (each row turns into a table of key/value pairs)\n- `-t`, `--truncate` truncate data instead of wrapping if too long for the terminal width\n- `-v`, `--version` prints version information\n\n## Compatible JSON Formats\n`jtbl` works best with a shallow array of JSON objects. Each object should have a few elements that will be turned into table columns. Fortunately, this is how many APIs present their data.\n\n**JSON Array Example**\n```\n[\n  {\n    \"unit\": \"proc-sys-fs-binfmt_misc.automount\",\n    \"load\": \"loaded\",\n    \"active\": \"active\",\n    \"sub\": \"waiting\",\n    \"description\": \"Arbitrary Executable File Formats File System Automount Point\"\n  },\n  {\n    \"unit\": \"sys-devices-pci0000:00-0000:00:07.1-ata2-host2-target2:0:0-2:0:0:0-block-sr0.device\",\n    \"load\": \"loaded\",\n    \"active\": \"active\",\n    \"sub\": \"plugged\",\n    \"description\": \"VMware_Virtual_IDE_CDROM_Drive\"\n  },\n  ...\n]\n```\n\n`jtbl` can also work with [JSON Lines](http://jsonlines.org/) format with similar features.\n\n**JSON Lines Example**\n```\n{\"name\": \"docker0\", type\": \"Ethernet\", \"ipv4_addr\": \"172.17.0.1\", \"ipv4_mask\": \"255.255.0.0\"}\n{\"name\": \"ens33\", \"type\": \"Ethernet\", \"ipv4_addr\": \"192.168.71.146\", \"ipv4_mask\": \"255.255.255.0\"}\n{\"name\": \"lo\", \"type\": \"Local Loopback\", \"ipv4_addr\": \"127.0.0.1\", \"ipv4_mask\": \"255.0.0.0\"}\n...\n```\n\n## Filtering the JSON Input\nIf there are too many elements, or the data in the elements are too large, the table may not fit in the terminal screen. In this case you can use a JSON filter like `jq` or `jello` to send `jtbl` only the elements you are interested in:\n\n### `jq` Array Method\nThe following example uses `jq` to filter and format the filtered elements into a proper JSON array.\n```\n$ cat /etc/passwd | jc --passwd | jq '[.[] | {username, shell}]'\n[\n  {\n    \"username\": \"root\",\n    \"shell\": \"/bin/bash\"\n  },\n  {\n    \"username\": \"bin\",\n    \"shell\": \"/sbin/nologin\"\n  },\n  {\n    \"username\": \"daemon\",\n    \"shell\": \"/sbin/nologin\"\n  },\n  ...\n]\n```\n*(Notice the square brackets around the filter)*\n\n### `jq` Slurp Method\nThe following example uses `jq` to filter and 'slurp' the filtered elements into a proper JSON array.\n```\n$ cat /etc/passwd | jc --passwd | jq '.[] | {username, shell}' | jq -s\n[\n  {\n    \"username\": \"root\",\n    \"shell\": \"/bin/bash\"\n  },\n  {\n    \"username\": \"bin\",\n    \"shell\": \"/sbin/nologin\"\n  },\n  {\n    \"username\": \"daemon\",\n    \"shell\": \"/sbin/nologin\"\n  },\n  ...\n]\n```\n*(Notice the `jq -s` at the end)*\n\n### `jq` JSON Lines Method\nThe following example will send the data in JSON Lines format, which `jtbl` can understand:\n```\n$ cat /etc/passwd | jc --passwd | jq -c '.[] | {username, shell}'\n{\"username\":\"root\",\"shell\":\"/bin/bash\"}\n{\"username\":\"bin\",\"shell\":\"/sbin/nologin\"}\n{\"username\":\"daemon\",\"shell\":\"/sbin/nologin\"}\n...\n```\n*(Notice the `-c` option being used)*\n\n### `jello` List Comprehension Method\nIf you prefer python list and dictionary syntax to filter JSON data, you can use `jello`:\n```\n$ cat /etc/passwd | jc --passwd | jello '[{\"username\": x.username, \"shell\": x.shell} for x in _]'\n[\n  {\n    \"username\": \"root\",\n    \"shell\": \"/bin/bash\"\n  },\n  {\n    \"username\": \"bin\",\n    \"shell\": \"/sbin/nologin\"\n  },\n  {\n    \"username\": \"daemon\",\n    \"shell\": \"/sbin/nologin\"\n  },\n  ...\n]\n```\n\nWhen piping any of these to `jtbl` you get the following result:\n```\n$ cat /etc/passwd | jc --passwd | jello '[{\"username\": x.username, \"shell\": x.shell} for x in _]' | jtbl\nusername         shell\n---------------  --------------\nroot             /bin/bash\nbin              /sbin/nologin\ndaemon           /sbin/nologin\n...\n```\n\n## Working with Deeper JSON Structures\n`jtbl` will happily dump deeply nested JSON structures into a table, but usually this is not what you are looking for.\n```\n$ jc dig www.cnn.com | jtbl\n╒══════════╤══════════╤═══════╤════════════╤═════════════╤══════════════╤══════════════╤══════════════╤══════════════╤════════════╤════════════╤══════════════╤════════════╤════════════╤════════╤══════════════╤══════════════╕\n│ opcode   │ status   │    id │ flags      │   query_num │   answer_num │   authority_ │   additional │ opt_pseudo   │ question   │ answer     │   query_time │ server     │ when       │   rcvd │   when_epoch │ when_epoch   │\n│          │          │       │            │             │              │          num │         _num │ section      │            │            │              │            │            │        │              │ _utc         │\n╞══════════╪══════════╪═══════╪════════════╪═════════════╪══════════════╪══════════════╪══════════════╪══════════════╪════════════╪════════════╪══════════════╪════════════╪════════════╪════════╪══════════════╪══════════════╡\n│ QUERY    │ NOERROR  │ 36494 │ ['qr', 'rd │           1 │            4 │            0 │            1 │ {'edns': {   │ {'name': ' │ [{'name':  │           47 │ 2600:1700: │ Wed Dec 22 │    100 │   1640200072 │              │\n│          │          │       │ ', 'ra']   │             │              │              │              │ 'version':   │ cnn.com.', │ 'cnn.com.' │              │ bab0:d40:: │  11:07:52  │        │              │              │\n│          │          │       │            │             │              │              │              │  0, 'flags   │  'class':  │ , 'class': │              │ 1#53(2600: │ PST 2021   │        │              │              │\n│          │          │       │            │             │              │              │              │ ': [], 'ud   │ 'IN', 'typ │  'IN', 'ty │              │ 1700:bab0: │            │        │              │              │\n│          │          │       │            │             │              │              │              │ p': 4096}}   │ e': 'A'}   │ pe': 'A',  │              │ d40::1)    │            │        │              │              │\n│          │          │       │            │             │              │              │              │              │            │ 'ttl': 60, │              │            │            │        │              │              │\n│          │          │       │            │             │              │              │              │              │            │  'data': ' │              │            │            │        │              │              │\n│          │          │       │            │             │              │              │              │              │            │ 151.101.12 │              │            │            │        │              │              │\n│          │          │       │            │             │              │              │              │              │            │ 9.67'}, {' │              │            │            │        │              │              │\n│          │          │       │            │             │              │              │              │              │            │ name': 'cn │              │            │            │        │              │              │\n│          │          │       │            │             │              │              │              │              │            │ n.com.', ' │              │            │            │        │              │              │\n│          │          │       │            │             │              │              │              │              │            │ class': 'I │              │            │            │        │              │              │\n│          │          │       │            │             │              │              │              │              │            │ ...        │              │            │            │        │              │              │\n╘══════════╧══════════╧═══════╧════════════╧═════════════╧══════════════╧══════════════╧══════════════╧══════════════╧════════════╧════════════╧══════════════╧════════════╧════════════╧════════╧══════════════╧══════════════╛\n```\n\n## Diving Deeper into the JSON with `jq` or `jello`:\nTo get to the data you are interested in you can use a JSON filter like `jq` or `jello` to dive deeper.\n\nUsing `jq`:\n```\n$ jc dig www.cnn.com | jq '.[0].answer'\n```\nor with `jello`:\n```\n$ jc dig www.cnn.com | jello '_[0].answer'\n```\nBoth will produce the following output:\n```\n[\n  {\n    \"name\": \"www.cnn.com.\",\n    \"class\": \"IN\",\n    \"type\": \"CNAME\",\n    \"ttl\": 90,\n    \"data\": \"turner-tls.map.fastly.net.\"\n  },\n  {\n    \"name\": \"turner-tls.map.fastly.net.\",\n    \"class\": \"IN\",\n    \"type\": \"A\",\n    \"ttl\": 20,\n    \"data\": \"151.101.1.67\"\n  }\n  ...\n]\n```\n\nThis will produce the following table in `jtbl`\n```\n$ jc dig www.cnn.com | jello '_[0].answer' | jtbl\nname                        class    type      ttl  data\n--------------------------  -------  ------  -----  --------------------------\nwww.cnn.com.                IN       CNAME      11  turner-tls.map.fastly.net.\nturner-tls.map.fastly.net.  IN       A          23  151.101.129.67\nturner-tls.map.fastly.net.  IN       A          23  151.101.1.67\nturner-tls.map.fastly.net.  IN       A          23  151.101.65.67\nturner-tls.map.fastly.net.  IN       A          23  151.101.193.67\n\n```\n\n## Column Width\n`jtbl` will attempt to shrink columns to a sane size if it detects the output is wider than the terminal width. The `--cols` option will override the automatic terminal width detection.\n\nYou can use the `-t` option to truncate the rows instead of wrapping when the terminal width is too small for all of the data.\n\nThe `-n` option disables wrapping and overrides the `--cols` and `-t` options.\n\nThis can be useful to present a nicely non-wrapped table of infinite width in combination with `less -S`:\n```\n$ jc ps aux | jtbl -n | less -S\nuser                  pid        vsz     rss  tt    stat    started    time       command\n------------------  -----  ---------  ------  ----  ------  ---------  ---------  ---------------------------------------------------\njoeuser             34029    4277364   24800  s000  S+      9:28AM     0:00.27    /usr/local/Cellar/python/3.7.6_1/Frameworks/Python....\njoeuser             34030    4283136   17104  s000  S+      9:28AM     0:00.20    /usr/local/Cellar/python/3.7.6_1/Frameworks/Python....\njoeuser               481    5728568  189328        S       17Apr20    21:46.52   /Applications/Utilities/Terminal.app/Contents/MacOS...\njoeuser             45827    6089084  693768        S       Wed01PM    84:54.87   /Applications/Microsoft Teams.app/Contents/Framewor...\njoeuser              1493    9338824  911600        S       17Apr20    143:27.08  /Applications/Microsoft Outlook.app/Contents/MacOS/...\njoeuser             45822    5851524  163840        S       Wed01PM    38:48.83   /Applications/Microsoft Teams.app/Contents/MacOS/Te...\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkellyjonbrazil%2Fjtbl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkellyjonbrazil%2Fjtbl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkellyjonbrazil%2Fjtbl/lists"}