wlezzar/jtab

A tiny command line tool written in rust to print json data as a formatted...

A tiny command line tool written in rust to print json data as a formatted table

Jtab

.

echo '[{"id": "1", "name": "Rust"}, {"id": "2", "name": "Jtab"}]' | jtab

┌────┬──────┐
│ id │ name │
├────┼──────┤
│ 1  │ Rust │
├────┼──────┤
│ 2  │ Jtab │
└────┴──────┘

Nested data is handled correctly.

 echo '[{"id": 1, "nested": {"value1": 1, "value2": 2}}, {"id": 2, "nested": {"array": [1, 2], "deeply_nested": {"value": 1}}}]' | jtab

┌────┬────────────────┐
 id  nested         
├────┼────────────────┤
 1   value1: 1      
     value2: 2      
├────┼────────────────┤
 2   array:         
       - 1          
       - 2          
     deeply_nested: 
       value: 1     
└────┴────────────────┘

Install

Using Homebrew (MacOs & Linux)

brew tap wlezzar/jtab https://github.com/wlezzar/jtab
brew install wlezzar/jtab/jtab

# use jtab
jtab --help

Using prebuilt binaries

Linux and Macos binaries are available as tarballs in the release section.

Using cargo (all platforms)

For other platforms, you can use cargo:

cargo install --git https://github.com/wlezzar/jtab

jtab --help

Sample commands

Example usage

Pipe some weather data into jtab:

➜ curl -s 'https://www.metaweather.com/api/location/search/?query=san' \
    | jtab

┌───────────────────────┬───────────────┬───────────────┬─────────┐
│ latt_long             │ location_type │ title         │ woeid   │
├───────────────────────┼───────────────┼───────────────┼─────────┤
│ 37.777119, -122.41964 │ City          │ San Francisco │ 2487956 │
├───────────────────────┼───────────────┼───────────────┼─────────┤
│ 32.715691,-117.161720 │ City          │ San Diego     │ 2487889 │
├───────────────────────┼───────────────┼───────────────┼─────────┤
│ 37.338581,-121.885567 │ City          │ San Jose      │ 2488042 │
├───────────────────────┼───────────────┼───────────────┼─────────┤
│ 29.424580,-98.494614  │ City          │ San Antonio   │ 2487796 │
├───────────────────────┼───────────────┼───────────────┼─────────┤
│ 36.974018,-122.030952 │ City          │ Santa Cruz    │ 2488853 │
└───────────────────────┴───────────────┴───────────────┴─────────┘

Take only 2 rows and a subset of the columns:

➜ curl -s 'https://www.metaweather.com/api/location/search/?query=san' \
    | jtab --take 2 -f title -f woeid

┌───────────────┬─────────┐
│ title         │ woeid   │
├───────────────┼─────────┤
│ San Francisco │ 2487956 │
├───────────────┼─────────┤
│ San Diego     │ 2487889 │
└───────────────┴─────────┘

Ingesting a stream of json (one json per row)

By default, jtab parses the full payload before printing it and expects it to be a valid JSON. To support use cases where data is piped in streaming mode (one valid json per line), jtab has a --streaming flag for that purpose.

The example below shows how you can use the --streaming flag to ingest the wikipedia change stream in jtab:

➜ curl -s  https://stream.wikimedia.org/v2/stream/recentchange \
    | grep data \
    | sed 's/^data: //g' \
    | jtab --streaming --take 5 -f id -f title -f user -f type

┌────────────┬───────────────────────────────────────────────────────┬───────────────────┬────────────┐
│ id         │ title                                                 │ user              │ type       │
├────────────┼───────────────────────────────────────────────────────┼───────────────────┼────────────┤
│ 1248099852 │ Q695926                                               │ Ecchbz            │ edit       │
├────────────┼───────────────────────────────────────────────────────┼───────────────────┼────────────┤
│ 98274450   │ Bản mẫu:Số ca nhiễm COVID-19 theo tinh thành Việt Nam │ Thái Nhi          │ edit       │
├────────────┼───────────────────────────────────────────────────────┼───────────────────┼────────────┤
│ 1272589900 │ Category:Noindexed pages                              │ Materialscientist │ categorize │
├────────────┼───────────────────────────────────────────────────────┼───────────────────┼────────────┤
│ 1272589899 │ Tong Tau Po                                           │ Underwaterbuffalo │ new        │
├────────────┼───────────────────────────────────────────────────────┼───────────────────┼────────────┤
│ 1272589901 │ Category:Wikipedia sockpuppets                        │ Materialscientist │ categorize │
└────────────┴───────────────────────────────────────────────────────┴───────────────────┴────────────┘

Table formats

jtab support multiple table formats using the --format command line option:

  • default: prints the table in a pretty formatted (to be used in the command line).
  • markdown: outputs the table in markdown
  • html: outputs the table in Html format styled with bootstrap
  • html-raw: outputs the table in Html format without any styling.

For example, to print the table in HTML format:

echo '[{"id": 1, "nested": {"value1": 1, "value2": 2}}, {"id": 2, "nested": {"array": [1, 2], "deeply_nested": {"value": 1}}}]' \
    | jtab --format html > /tmp/table.html
  
# Open the file with your favorite browser  
➜ xdg-open /tmp/table.html

Conditionally colorize fields (only supported with --format default)

You can conditionally colorize some fields based on their value:

➜  ~ curl -s  https://stream.wikimedia.org/v2/stream/recentchange \
         | grep data \
         | sed 's/^data: //g' \
         | jtab --streaming --take 5 -f id -f title -f user -f type \
                --colorize 'type:categorize:bFg' \
                --colorize 'type:edit:bFr'

The colorize option takes a string in the format column_name:value:style_spec. The style_spec corresponds to the style specifiers of the prettytable-rs library that jtab is based on.

Versions

Find the latest versions by id

v0.4.5 - Oct 29, 2021

Fix homebrew package

v0.4.4 - Dec 31, 2020

v0.4.3 - Dec 31, 2020

v0.4.2 - Dec 31, 2020

v0.4.1 - Dec 31, 2020

v0.4.0 - Dec 29, 2020

This release brings support to a new HTML format for the tables:

v0.3.0 - Jun 16, 2020

v0.2.0 - Jun 15, 2020

v0.1.0 - Jun 15, 2020

Information - Updated Jul 06, 2022

Stars: 38
Forks: 1
Issues: 0

Repositories & Extras

Serde is a framework for serializing and deserializing Rust data structures efficiently and generically

Rust Greatest JSON weapon is Serde with over 4.4K stars on github and a massive developer community. This is considered a core Rust library for every developer to learn in BRC's opinion

Serde is a framework for serializing and deserializing Rust data structures efficiently and generically

Rust 버전 JsonPath 구현으로 Webassembly와 Javascript에서도 유사한 API 인터페이스를 제공 한다

JsonPath 구현으로 Webassembly와 Javascript에서도 유사한 API 인터페이스를 제공 한다

Rust 버전 JsonPath 구현으로 Webassembly와 Javascript에서도 유사한 API 인터페이스를 제공 한다

SIMD JSON for Rust  

Rust port of extremely fast serde compatibility

SIMD JSON for Rust  

JSON-E Rust data-struct paramter crate for lightweight embedded content with objects and much more

What makes JSON-e unique is that it extensive documentation and ease of use

JSON-E Rust data-struct paramter crate for lightweight embedded content with objects and much more
JSON

111

A Rust JSON5 serializer and deserializer which speaks Serde

Deserialize a JSON5 string with from_str

A Rust JSON5 serializer and deserializer which speaks Serde

Rust JSON Parser Benchmark

Download and Generate JSON Data

Rust JSON Parser Benchmark

Read JSON values quickly - Rust JSON Parser

AJSON get json value with specified path, such as project

Read JSON values quickly - Rust JSON Parser

Rust actix json request example

Send a json request to actix, and parse it

Rust actix json request example
JSON

140

json_typegen - Rust types from JSON samples

json_typegen is a collection of tools for generating types from

json_typegen - Rust types from JSON samples

Rust JSON parsing benchmarks

This project aims to provide benchmarks to show how various JSON-parsing libraries in the Rust programming language perform at various JSON-parsing tasks

Rust JSON parsing benchmarks

Rust RPC client for Bitcoin Core JSON-RPC

rust-jsonrpc and makes it easier to talk to the Bitcoin JSON-RPC interface

Rust RPC client for Bitcoin Core JSON-RPC
Facebook Instagram Twitter GitHub Dribbble
Privacy