jc - Man Page

JSONifies the output of many CLI tools and file-types

Examples (TL;DR)

Synopsis

COMMAND | jc PARSER [Options]

or "Magic" syntax:

jc [Options] COMMAND

Description

jc JSONifies the output of many CLI tools and file-types for easier parsing in scripts. jc accepts piped input from STDIN and outputs a JSON representation of the previous command's output to STDOUT. Alternatively, the "Magic" syntax can be used by prepending jc to the command to be converted. Options can be passed to jc immediately before the command is given. (Note: "Magic" syntax does not support shell builtins or command aliases)

Options

Parsers:

--acpi

`acpi` command parser

--airport

`airport -I` command parser

--airport-s

`airport -s` command parser

--arp

`arp` command parser

--blkid

`blkid` command parser

--cksum

`cksum` and `sum` command parser

--crontab

`crontab` command and file parser

--crontab-u

`crontab` file parser with user support

--csv

CSV file parser

--date

`date` command parser

--df

`df` command parser

--dig

`dig` command parser

--dir

`dir` command parser

--dmidecode

`dmidecode` command parser

--dpkg-l

`dpkg -l` command parser

--du

`du` command parser

--env

`env` command parser

--file

`file` command parser

--finger

`finger` command parser

--free

`free` command parser

--fstab

`/etc/fstab` file parser

--group

`/etc/group` file parser

--gshadow

`/etc/gshadow` file parser

--hash

`hash` command parser

--hashsum

hashsum command parser (`md5sum`, `shasum`, etc.)

--hciconfig

`hciconfig` command parser

--history

`history` command parser

--hosts

`/etc/hosts` file parser

--id

`id` command parser

--ifconfig

`ifconfig` command parser

--ini

INI file parser

--iptables

`iptables` command parser

--iw-scan

`iw dev [device] scan` command parser

--jobs

`jobs` command parser

--kv

Key/Value file parser

--last

`last` and `lastb` command parser

--ls

`ls` command parser

--lsblk

`lsblk` command parser

--lsmod

`lsmod` command parser

--lsof

`lsof` command parser

--mount

`mount` command parser

--netstat

`netstat` command parser

--ntpq

`ntpq -p` command parser

--passwd

`/etc/passwd` file parser

--ping

`ping` and `ping6` command parser

--pip-list

`pip list` command parser

--pip-show

`pip show` command parser

--ps

`ps` command parser

--route

`route` command parser

--rpm-qi

`rpm -qi` command parser

--sfdisk

`sfdisk` command parser

--shadow

`/etc/shadow` file parser

--ss

`ss` command parser

--stat

`stat` command parser

--sysctl

`sysctl` command parser

--systemctl

`systemctl` command parser

--systemctl-lj

`systemctl list-jobs` command parser

--systemctl-ls

`systemctl list-sockets` command parser

--systemctl-luf

`systemctl list-unit-files` command parser

--systeminfo

`systeminfo` command parser

--time

`/usr/bin/time` command parser

--timedatectl

`timedatectl status` command parser

--tracepath

`tracepath` and `tracepath6` command parser

--traceroute

`traceroute` and `traceroute6` command parser

--ufw

`ufw status` command parser

--ufw-appinfo

`ufw app info [application]` command parser

--uname

`uname -a` command parser

--upower

`upower` command parser

--uptime

`uptime` command parser

--w

`w` command parser

--wc

`wc` command parser

--who

`who` command parser

--xml

XML file parser

--yaml

YAML file parser

Options:

-a

about jc (JSON output)

-d

debug - show traceback (-dd for verbose traceback)

-h

help (-h --parser_name for parser documentation)

-m

monochrome output

-p

pretty print output

-q

quiet - suppress warnings

-r

raw JSON output

-v

version information

Exit Codes

Any fatal errors within jc will generate an exit code of 100, otherwise the exit code will be 0. When using the "Magic" syntax (e.g. jc ifconfig eth0), jc will store the exit code of the program being parsed and add it to the  jc exit code. This way it is easier to determine if an error was from the parsed program or jc.

Consider the following examples using `ifconfig`:

ifconfig exit code = 0, jc exit code = 0, combined exit code = 0 (no errors)

ifconfig exit code = 1, jc exit code = 0, combined exit code = 1 (error in ifconfig)

ifconfig exit code = 0, jc exit code = 100, combined exit code = 100 (error in jc)

ifconfig exit code = 1, jc exit code = 100, combined exit code = 101 (error in both ifconfig and jc)

Environment

You can specify custom colors via the JC_COLORS environment variable. The JC_COLORS environment variable takes four comma separated string values in the following format:

JC_COLORS=<keyname_color>,<keyword_color>,<number_color>,<string_color>

Where colors are: black, red, green, yellow, blue, magenta, cyan, gray, brightblack, brightred, brightgreen, brightyellow, brightblue, brightmagenta, brightcyan, white, or default

For example, to set to the default colors:

JC_COLORS=blue,brightblack,magenta,green

or

JC_COLORS=default,default,default,default

Custom Parsers

Custom local parser plugins may be placed in a jc/jcparsers folder in your local "App data directory":

Local parser plugins are standard python module files. Use the jc/parsers/foo.py parser as a template and simply place a .py file in the jcparsers subfolder.

Local plugin filenames must be valid python module names, therefore must consist entirely of alphanumerics and start with a letter. Local plugins may override default plugins.

Note: The application data directory follows the XDG Base Directory Specification

Caveats

Locale: For best results set the LANG locale environment variable to C or en_US.UTF-8. For example, either by setting directly on the command-line:

$ LANG=C date | jc --date

or by exporting to the environment before running commands:

$ export LANG=C

Timezones: Some parsers have calculated epoch timestamp fields added to the output. Unless a timestamp field name has a _utc suffix it is considered naive. (i.e. based on the local timezone of the system the jc parser was run on).

If a UTC timezone can be detected in the text of the command output, the timestamp will be timezone aware and have a _utc suffix on the key name. (e.g. epoch_utc) No other timezones are supported for aware timestamps.

Examples

Standard Syntax:

$ dig www.google.com | jc --dig -p

Magic Syntax:

$ jc -p dig www.google.com

For parser documentation:

$ jc -h --dig

Author

Kelly Brazil (kellyjonbrazil@gmail.com)

https://github.com/kellyjonbrazil/jc

Info

2021-07-20 1.16.0 JSON CLI output utility