LinuxCommandLibrary

jtbl

Display jump tables from ELF files

TLDR

Print a table from JSON or JSON Lines input

$ cat [file.json] | jtbl
copy

Print a table and specify the column width for wrapping
$ cat [file.json] | jtbl --cols=[width]
copy

Print a table and truncate rows instead of wrapping
$ cat [file.json] | jtbl [[-t|--truncate]]
copy

Print a table and don't wrap or truncate rows
$ cat [file.json] | jtbl [[-n|--no-wrap]]
copy

SYNOPSIS

jtbl [options] [file...]

PARAMETERS

-c columns
    Specifies a comma-separated list of column names to display.
This allows for reordering or selecting a subset of available columns.

-C header
    Uses the provided string as a single header for all columns,
overriding automatically detected headers.

-i
    Ignores missing columns. If a specified column
is not found in a JSON object, it will be treated as empty
instead of causing an error.

-H
    Outputs the table in HTML format.

-M
    Outputs the table in Markdown format.

-S
    Outputs the table as SQL INSERT statements.

-L
    Outputs the table in LaTeX format.

-s
    Outputs the table in plain text format (this is the default).

-f key
    Extracts a specific top-level field/key from each JSON object
and uses its content as the data source for the table.

-d delimiter
    Specifies a custom delimiter character for
plain text or CSV output (default is space or comma respectively).

-t
    Forces the output of a table header, even if no
columns are explicitly specified or detected.

-nh
    Suppresses the output of the header row.

-ns
    Suppresses the separator line in plain text table output.

-nr
    Suppresses row numbers in the output.

-o output_file
    Writes the generated table output to the specified file
instead of standard output.

-x
    Escapes output values, particularly useful for
HTML to prevent injection issues or ensure proper display.

-v
    Enables verbose output, showing more information
about the processing.

-V, --version
    Prints the version information of jtbl and exits.

--help
    Displays a help message with usage instructions and options, then exits.

--
    Marks the end of command-line options, allowing subsequent arguments
to be treated as filenames even if they start with a hyphen.

DESCRIPTION

The jtbl command is a specialized utility designed to transform
JSON data into various human-readable or machine-readable table formats.
It is a companion tool to jo (JSON output) and is typically used
to process JSON arrays of objects, where each object represents a row
and its keys correspond to column headers.

jtbl reads JSON from standard input or specified files and
can generate output in formats such as plain text,
Comma-Separated Values (CSV), HTML, Markdown, SQL INSERT statements,
or LaTeX tables. This makes it highly versatile for
data presentation, report generation, or database import tasks.

Users can specify which columns to include,
define custom headers, and control the output styling.
It's particularly useful in shell scripting pipelines
where structured JSON output from other commands
needs to be quickly formatted for display or further processing.
Its ability to handle missing columns gracefully
and escape output values for web contexts
adds to its robustness.

CAVEATS

It is important to note that jtbl is
not a standard utility found in most
core GNU/Linux distributions. It typically requires
separate installation, usually as part of the jo
(JSON output) package.

The command expects valid JSON input,
specifically an array of JSON objects, where each object
represents a row of data.
Incorrect JSON formatting or a different structure
may lead to errors or unexpected output.

TYPICAL USAGE WITH JO

jtbl is frequently used in conjunction with
jo to create and then format JSON data.
For example, jo -a name=Alice age=30 | jtbl
would create a JSON array with one object and
then format it into a plain text table.

EXPECTED JSON INPUT STRUCTURE

For jtbl to function correctly, the input
JSON should typically be an array of objects.
Each object within the array is treated as a row,
and the keys within each object are interpreted as
column headers. For instance:
[{"name":"Bob", "age":25}, {"name":"Charlie", "age":35}]
would result in a table with 'name' and 'age' columns.

HISTORY

The jtbl utility is a component of the
jo project, an open-source initiative by
J.P. Mens. jo was initially released around
2017 with the aim of simplifying JSON generation
from the command line. jtbl was developed
as a complementary tool to provide structured
table formatting capabilities for the JSON
output produced by jo or other sources.
Its development reflects a growing need for
flexible command-line tools to process and present
JSON data in various contexts.

SEE ALSO

jo(1), jq(1), column(1), csvlook(1)

Copied to clipboard