kellyjonbrazil / jtbl Goto Github PK
View Code? Open in Web Editor NEWCLI tool to convert JSON and JSON Lines to terminal, CSV, HTTP, and markdown tables
License: MIT License
CLI tool to convert JSON and JSON Lines to terminal, CSV, HTTP, and markdown tables
License: MIT License
File "/home/kbrazil/.local/lib/python3.6/site-packages/jtbl/cli.py", line 68, in main
entry[k] = '\n'.join([str(v)[i:i + wrap_width] for i in range(0, len(str(v)), wrap_width)])
ValueError: range() arg 3 must not be zero
This happened on a serial console - maybe shutil wasn't able to determine terminal size. Can probably fix by setting a default value to wrap_width
in case shutil fails.
Hi. Can you add an option to sort columns in a table?
Now:
curl --silent http://<my-repo-in-intranet>/apt/debian/dists/stable/main/binary-amd64/Packages | /usr/local/bin/jc --pkg-index-deb -p | /usr/local/bin/jp "sort_by([], &package)[].{package: package, version: version, homepage: homepage}" | /usr/local/bin/jtbl --markdown
| homepage | package | version |
|------------------------------------------------|--------------|------------|
| https://schollz.com/software/croc/ | croc | 9.6.6 |
| https://github.com/jgraph/drawio | draw.io | 22.1.2 |
| | ifcplugin | 3.1.1.0 |
| https://github.com/kellyjonbrazil/jc | jc | 1.24.0-1 |
| https://github.com/kellyjonbrazil/jtbl | jtbl | 1.6.0-1 |
| | naps2 | 7.2.1 |
| | pandoc | 3.1.11-1 |
| https://rclone.org | rclone | 1.65.0 |
| | scenebuilder | 21.0.0 |
| https://github.com/ansible-semaphore/semaphore | semaphore | 2.9.37 |
| www.hamrick.com | vuescan | 9.8.22.0-0 |
How i want:
jtbl --markdown --order=package,version,homepage
| package | version | homepage |
|---------------|---------------|------------------------------------------------|
| croc | 9.6.6 | https://schollz.com/software/croc/ |
| draw.io | 22.1.2 | https://github.com/jgraph/drawio |
| ifcplugin | 3.1.1.0 | |
| jc | 1.24.0-1 | https://github.com/kellyjonbrazil/jc |
| jtbl | 1.6.0-1 | https://github.com/kellyjonbrazil/jtbl |
| naps2 | 7.2.1 | |
| pandoc | 3.1.11-1 | |
| rclone | 1.65.0 | https://rclone.org |
| scenebuilder | 21.0.0 | |
| semaphore | 2.9.37 | https://github.com/ansible-semaphore/semaphore |
| vuescan | 9.8.22.0-0 | www.hamrick.com |
Instead of wrapping, truncate large fields with something like jtbl -t
This would make the table even more readable in Markdown documents or Github issues because it would be rendered as a proper HTML table.
It would be great if the changelog was included in the PyPI package. It's useful for when including documentation in distribution packages.
Hi!
Can you add bash completion as in the jc
project?
Thanks for this tool! Would there be a way to make jtbl
recognize that values separated by commas within square brackets should be on new lines, with json
files of the following structure?
{
"Date": [
"2021-08-24 21:00:00",
"2021-08-24 21:00:00",
"2021-08-24 21:00:00",
"2021-08-24 21:00:00",
"2021-08-24 21:00:00",
"2021-08-24 21:00:00",
"2021-08-24 21:00:00",
"2021-08-24 21:00:00",
"2021-08-24 21:00:00",
"2021-08-24 21:00:00",
"2021-08-24 21:00:00",
"2021-08-24 21:00:00",
"2021-08-24 21:00:00"
],
"Location": [
"Indonesia - TERNATE/BABULLAH",
"Bolivia - TRINIDAD",
"United States - PENSACOLA, FL",
"Russian Federation - IVDEL'",
"India - GULBARGA",
"Honduras - CHOLUTECA",
"United States - JACKSONVILLE/INTNL., FL.",
"Honduras - LA MESA (SAN PEDRO SULA)",
"Russian Federation - JARCEVO",
"Russian Federation - VEL' MO",
"Azerbaijan - GUBA",
"Niger - NIAMEY-AERO",
"Vietnam - PHU LIEN"
]
}
Currently, when I pipe that into jtbl
, it just shows a table with two columns and a single row containing all values separated by commas.
Is there a way to suppress the scientific notation that sometimes appears in the output?
I'd like jtbl to use the same notation as the source.
Here's a simple example of the surprising behavior:
$ jq -n '{"a": 1000000, "b": 1000000.1}' | jtbl -m
| a | b |
|---------|-------|
| 1000000 | 1e+06 |
Is there something I'm missing?
Hi Kelly hope you're good ๐
I thought maybe it was cool if we had a csv output. Let me know what you think <3
Right now auto-scaling the column width to fit inside the terminal is pretty rudimentary.
I'm adding up all of the longest items, whether the header or the data values, seeing if they are larger than the terminal width and then setting a maximum column width that should allow the table to fit if all columns are the same size.
Since some columns are smaller than the evenly divided column length this doesn't always fully fill the terminal width.
There is also no logic to do something different if the table is clearly too wide to ever fit, no matter how small the columns get. Maybe need to remove columns that would fall off the screen.
Wondering if this problem has already been solved somehow. I'll continue to make incremental improvements, but if someone else knows how to solve this I'm open to ideas.
This will help large tables without truncating
Hi!
Can you add a long key format to use in scripts?
Now:
jtbl: Converts JSON and JSON Lines to a table
Usage: <JSON Data> | jtbl [OPTIONS]
--cols=n manually configure the terminal width
-c CSV table output
-f fancy table output
-h help
-H HTML table output
-m markdown table output
-n no-wrap - do not try to wrap if too wide for the terminal
-q quiet - don't print error messages
-r rotate table output
-t truncate data if too wide for the terminal
-v version info
How i want:
jtbl: Converts JSON and JSON Lines to a table
Usage: <JSON Data> | jtbl [OPTIONS]
--cols=n manually configure the terminal width
-c, --csv CSV table output
-f, --fancy fancy table output
-h, --help help
-H, --html HTML table output
-m, --markdown markdown table output
-n, --no-wrap no-wrap - do not try to wrap if too wide for the terminal
-q, --quiet quiet - don't print error messages
-r, --rotate rotate table output
-t, --truncate truncate data if too wide for the terminal
-v, --version version info
I notice that jtbl
throws an error when it receives an empty list as input ([]
).
This feels like a bug since en empty list is considered valid json.
jtbl: version 1.5.1
echo "[]" | jtbl
An empty response (similar to what is returned when you send an empty object {}
.
Traceback (most recent call last):
File "/opt/homebrew/bin/jtbl", line 8, in <module>
sys.exit(main())
^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/jtbl/cli.py", line 339, in main
succeeded, json_data = check_data(json_data, columns=columns)
^^^^^^^^^^^^^^^^^^^^
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.
Gracefully exit on CTRL-C instead of generating a stack trace.
jtbl: Missing piped data
Would be nice if we can ignore this with a --quiet
or -q
So it doesn't output this. Sometimes our elaborate JQ pipelines result into 0 results and then just don't make a table.
Hi!
Can you add yet another table format? https://www.dokuwiki.org/wiki:syntax#tables
With -d,--dokuwiki
options.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.