2022-09-13 13:42:06 -07:00
.TH jc 1 2022 -09-13 1 .21.2 "JSON Convert"
2021-07-19 12:08:50 -07:00
.SH NAME
2022-09-07 13:56:16 -07:00
\fB jc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types, and strings
2021-07-19 12:08:50 -07:00
.SH SYNOPSIS
2022-09-07 13:56:16 -07:00
Standard syntax:
2021-07-19 12:08:50 -07:00
2022-09-07 13:56:16 -07:00
.RS
COMMAND | \fB jc\fP [OPTIONS] PARSER
cat FILE | \fB jc\fP [OPTIONS] PARSER
echo STRING | \fB jc\fP [OPTIONS] PARSER
.RE
Magic syntax:
.RS
2022-05-12 11:16:44 -07:00
\fB jc\fP [OPTIONS] COMMAND
2021-07-19 12:08:50 -07:00
2022-09-09 17:13:43 -07:00
\fB jc\fP [OPTIONS] /proc/<path-to-procfile>
2022-09-07 13:56:16 -07:00
.RE
2021-07-19 12:08:50 -07:00
.SH DESCRIPTION
2022-07-31 10:52:00 -07:00
\fB jc\fP JSONifies the output of many CLI tools, file-types, and common strings for easier parsing in scripts. \fB jc\fP accepts piped input from \fB STDIN\fP and outputs a JSON representation of the previous command's output to \fB STDOUT\fP . Alternatively, the "Magic" syntax can be used by prepending \fB jc\fP to the command to be converted. Options can be passed to \fB jc\fP immediately before the command is given. (Note: "Magic" syntax does not support shell builtins or command aliases)
2021-07-19 12:08:50 -07:00
.SH OPTIONS
.B
Parsers:
.RS
.TP
.B
\fB --acpi\fP
`acpi` command parser
.TP
.B
\fB --airport\fP
`airport -I` command parser
.TP
.B
\fB --airport-s\fP
`airport -s` command parser
.TP
.B
\fB --arp\fP
`arp` command parser
2022-03-22 12:25:59 -07:00
.TP
.B
\fB --asciitable\fP
ASCII and Unicode table parser
2022-03-22 07:05:14 -07:00
.TP
.B
\fB --asciitable-m\fP
multi-line ASCII and Unicode table parser
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --blkid\fP
`blkid` command parser
2022-08-12 10:16:15 -07:00
.TP
.B
\fB --cef\fP
CEF string parser
2022-08-20 13:30:39 -07:00
.TP
.B
\fB --cef-s\fP
CEF string streaming parser
2022-05-11 16:12:29 -07:00
.TP
.B
\fB --chage\fP
`chage --list` command parser
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --cksum\fP
`cksum` and `sum` command parser
.TP
.B
\fB --crontab\fP
`crontab` command and file parser
.TP
.B
\fB --crontab-u\fP
`crontab` file parser with user support
.TP
.B
\fB --csv\fP
CSV file parser
2021-10-24 13:10:47 -07:00
.TP
.B
\fB --csv-s\fP
CSV file streaming parser
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --date\fP
`date` command parser
.TP
.B
\fB --df\fP
`df` command parser
.TP
.B
\fB --dig\fP
`dig` command parser
.TP
.B
\fB --dir\fP
`dir` command parser
.TP
.B
\fB --dmidecode\fP
`dmidecode` command parser
.TP
.B
\fB --dpkg-l\fP
`dpkg -l` command parser
.TP
.B
\fB --du\fP
`du` command parser
2022-07-19 13:02:09 -07:00
.TP
.B
\fB --email-address\fP
Email Address string parser
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --env\fP
`env` command parser
.TP
.B
\fB --file\fP
`file` command parser
.TP
.B
\fB --finger\fP
`finger` command parser
.TP
.B
\fB --free\fP
`free` command parser
.TP
.B
\fB --fstab\fP
`/etc/fstab` file parser
2022-04-19 13:17:24 -04:00
.TP
.B
\fB --git-log\fP
`git log` command parser
2022-04-28 16:23:56 -07:00
.TP
.B
\fB --git-log-s\fP
`git log` command streaming parser
2022-06-29 18:36:06 -07:00
.TP
.B
\fB --gpg\fP
`gpg --with-colons` command parser
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --group\fP
`/etc/group` file parser
.TP
.B
\fB --gshadow\fP
`/etc/gshadow` file parser
.TP
.B
\fB --hash\fP
`hash` command parser
.TP
.B
\fB --hashsum\fP
hashsum command parser (`md5sum`, `shasum`, etc.)
.TP
.B
\fB --hciconfig\fP
`hciconfig` command parser
.TP
.B
\fB --history\fP
`history` command parser
.TP
.B
\fB --hosts\fP
`/etc/hosts` file parser
.TP
.B
\fB --id\fP
`id` command parser
.TP
.B
\fB --ifconfig\fP
`ifconfig` command parser
.TP
.B
\fB --ini\fP
INI file parser
2021-12-01 16:12:51 -08:00
.TP
.B
\fB --iostat\fP
`iostat` command parser
2021-12-02 11:42:56 -08:00
.TP
.B
\fB --iostat-s\fP
`iostat` command streaming parser
2022-07-27 17:21:04 -07:00
.TP
.B
\fB --ip-address\fP
2022-07-28 09:03:49 -07:00
IPv4 and IPv6 Address string parser
2022-07-27 17:21:04 -07:00
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --iptables\fP
`iptables` command parser
2022-07-20 17:09:09 -07:00
.TP
.B
\fB --iso-datetime\fP
ISO 8601 Datetime string parser
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --iw-scan\fP
`iw dev [device] scan` command parser
2022-01-02 11:00:52 -08:00
.TP
.B
\fB --jar-manifest\fP
2022-08-15 13:51:48 -07:00
Java MANIFEST.MF file parser
2022-01-02 11:00:52 -08:00
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --jobs\fP
`jobs` command parser
2022-07-19 15:24:38 -07:00
.TP
.B
\fB --jwt\fP
JWT string parser
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --kv\fP
Key/Value file parser
.TP
.B
\fB --last\fP
`last` and `lastb` command parser
.TP
.B
\fB --ls\fP
`ls` command parser
2021-09-10 14:27:50 -07:00
.TP
.B
\fB --ls-s\fP
`ls` command streaming parser
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --lsblk\fP
`lsblk` command parser
.TP
.B
\fB --lsmod\fP
`lsmod` command parser
.TP
.B
\fB --lsof\fP
`lsof` command parser
2021-10-23 11:56:12 -07:00
.TP
.B
\fB --lsusb\fP
`lsusb` command parser
2022-07-16 20:52:19 -07:00
.TP
.B
\fB --m3u\fP
M3U and M3U8 file parser
2022-08-12 10:16:15 -07:00
.TP
.B
\fB --mdadm\fP
`mdadm` command parser
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --mount\fP
`mount` command parser
.TP
2022-03-11 14:54:06 -08:00
.B
\fB --mpstat\fP
`mpstat` command parser
.TP
2022-03-11 15:59:38 -08:00
.B
\fB --mpstat-s\fP
`mpstat` command streaming parser
.TP
2021-07-19 12:08:50 -07:00
.B
\fB --netstat\fP
`netstat` command parser
2022-02-24 20:43:20 -08:00
.TP
.B
\fB --nmcli\fP
`nmcli` command parser
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --ntpq\fP
`ntpq -p` command parser
.TP
.B
\fB --passwd\fP
`/etc/passwd` file parser
2022-03-09 14:09:58 -08:00
.TP
.B
\fB --pidstat\fP
2022-05-28 13:13:07 -07:00
`pidstat -h` command parser
2022-03-09 14:09:58 -08:00
2022-03-09 16:09:35 -08:00
.TP
.B
\fB --pidstat-s\fP
2022-05-28 13:13:07 -07:00
`pidstat -h` command streaming parser
2022-03-09 16:09:35 -08:00
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --ping\fP
`ping` and `ping6` command parser
2021-09-13 21:14:38 -07:00
.TP
.B
\fB --ping-s\fP
`ping` and `ping6` command streaming parser
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --pip-list\fP
`pip list` command parser
.TP
.B
\fB --pip-show\fP
`pip show` command parser
2022-07-31 16:14:04 -07:00
.TP
.B
\fB --plist\fP
PLIST file parser
2022-06-05 17:40:05 -07:00
.TP
.B
\fB --postconf\fP
`postconf -M` command parser
2022-09-06 10:07:19 -07:00
.TP
.B
\fB --proc\fP
`/proc/` file parser
2022-09-06 15:19:59 -07:00
.TP
.B
\fB --proc-buddyinfo\fP
`/proc/buddyinfo` file parser
2022-09-06 15:52:26 -07:00
.TP
.B
\fB --proc-consoles\fP
`/proc/consoles` file parser
2022-09-06 17:05:14 -07:00
.TP
.B
\fB --proc-cpuinfo\fP
`/proc/cpuinfo` file parser
2022-09-06 17:29:56 -07:00
.TP
.B
\fB --proc-crypto\fP
`/proc/crypto` file parser
2022-09-06 17:59:26 -07:00
.TP
.B
\fB --proc-devices\fP
`/proc/devices` file parser
2022-09-06 15:19:59 -07:00
2022-09-09 14:33:12 -07:00
.TP
.B
\fB --proc-diskstats\fP
`/proc/diskstats` file parser
2022-09-09 16:28:34 -07:00
.TP
.B
\fB --proc-driver-rtc\fP
`/proc/driver_rtc` file parser
2022-09-09 17:03:51 -07:00
.TP
.B
\fB --proc-filesystems\fP
`/proc/filesystems` file parser
2022-09-13 13:42:06 -07:00
.TP
.B
\fB --proc-interrupts\fP
`/proc/interrupts` file parser
2022-09-06 10:07:19 -07:00
.TP
.B
\fB --proc-meminfo\fP
2022-09-06 15:19:59 -07:00
`/proc/meminfo` file parser
2022-09-06 10:07:19 -07:00
.TP
.B
\fB --proc-modules\fP
2022-09-06 15:19:59 -07:00
`/proc/modules` file parser
2022-09-06 10:07:19 -07:00
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --ps\fP
`ps` command parser
.TP
.B
\fB --route\fP
`route` command parser
.TP
.B
\fB --rpm-qi\fP
`rpm -qi` command parser
2022-02-01 17:57:12 -08:00
.TP
.B
\fB --rsync\fP
`rsync` command parser
2022-02-02 15:58:29 -08:00
.TP
.B
\fB --rsync-s\fP
`rsync` command streaming parser
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --sfdisk\fP
`sfdisk` command parser
.TP
.B
\fB --shadow\fP
`/etc/shadow` file parser
.TP
.B
\fB --ss\fP
`ss` command parser
.TP
.B
\fB --stat\fP
`stat` command parser
2022-01-06 11:00:53 -08:00
.TP
.B
\fB --stat-s\fP
`stat` command streaming parser
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --sysctl\fP
`sysctl` command parser
2022-08-16 16:33:50 -07:00
.TP
.B
\fB --syslog\fP
Syslog RFC 5424 string parser
.TP
.B
\fB --syslog-s\fP
Syslog RFC 5424 string streaming parser
2022-08-12 10:16:15 -07:00
.TP
.B
\fB --syslog-bsd\fP
Syslog RFC 3164 string parser
.TP
.B
2022-08-16 16:33:50 -07:00
\fB --syslog-bsd-s\fP
Syslog RFC 3164 string streaming parser
2022-08-12 10:16:15 -07:00
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --systemctl\fP
`systemctl` command parser
.TP
.B
\fB --systemctl-lj\fP
`systemctl list-jobs` command parser
.TP
.B
\fB --systemctl-ls\fP
`systemctl list-sockets` command parser
.TP
.B
\fB --systemctl-luf\fP
`systemctl list-unit-files` command parser
.TP
.B
\fB --systeminfo\fP
`systeminfo` command parser
.TP
.B
\fB --time\fP
`/usr/bin/time` command parser
.TP
.B
\fB --timedatectl\fP
`timedatectl status` command parser
2022-05-25 10:31:41 -07:00
2022-07-23 12:43:17 -07:00
.TP
.B
\fB --timestamp\fP
2022-08-04 11:43:49 -07:00
Unix Epoch Timestamp string parser
2022-07-23 12:43:17 -07:00
2022-05-25 10:31:41 -07:00
.TP
.B
\fB --top\fP
`top -b` command parser
2022-05-27 13:34:07 -07:00
.TP
.B
\fB --top-s\fP
`top -b` command streaming parser
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --tracepath\fP
`tracepath` and `tracepath6` command parser
.TP
.B
\fB --traceroute\fP
`traceroute` and `traceroute6` command parser
.TP
.B
\fB --ufw\fP
`ufw status` command parser
.TP
.B
\fB --ufw-appinfo\fP
`ufw app info [application]` command parser
.TP
.B
\fB --uname\fP
`uname -a` command parser
2022-04-22 15:23:11 -07:00
.TP
.B
\fB --update-alt-gs\fP
`update-alternatives --get-selections` command parser
.TP
.B
\fB --update-alt-q\fP
`update-alternatives --query` command parser
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --upower\fP
`upower` command parser
.TP
.B
\fB --uptime\fP
`uptime` command parser
2022-07-19 13:02:09 -07:00
.TP
.B
\fB --url\fP
URL string parser
2021-09-22 14:38:13 -07:00
.TP
.B
\fB --vmstat\fP
`vmstat` command parser
.TP
.B
\fB --vmstat-s\fP
`vmstat` command streaming parser
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --w\fP
`w` command parser
.TP
.B
\fB --wc\fP
`wc` command parser
.TP
.B
\fB --who\fP
`who` command parser
.TP
.B
2022-07-05 15:07:10 -07:00
\fB --x509-cert\fP
X.509 PEM and DER certificate file parser
2021-07-19 12:08:50 -07:00
2022-07-05 13:33:57 -07:00
.TP
.B
2022-07-05 15:07:10 -07:00
\fB --xml\fP
XML file parser
2022-07-05 13:33:57 -07:00
2022-02-14 09:14:46 -08:00
.TP
.B
\fB --xrandr\fP
`xrandr` command parser
2021-07-19 12:08:50 -07:00
.TP
.B
\fB --yaml\fP
YAML file parser
2021-12-21 12:14:20 -08:00
.TP
.B
\fB --zipinfo\fP
`zipinfo` command parser
2021-07-19 12:08:50 -07:00
.RE
.PP
.B
Options:
.RS
.TP
.B
2022-06-06 10:32:18 -07:00
\fB -a\fP , \fB --about\fP
2022-06-06 10:49:17 -07:00
About \fB jc\fP (JSON or YAML output)
2021-07-19 12:08:50 -07:00
.TP
.B
2022-06-06 10:32:18 -07:00
\fB -C\fP , \fB --force-color\fP
2022-06-06 10:49:17 -07:00
Force color output even when using pipes (overrides \fB -m\fP and the \fB NO_COLOR\fP env variable)
2021-12-08 08:22:28 -08:00
.TP
.B
2022-06-06 10:32:18 -07:00
\fB -d\fP , \fB --debug\fP
2022-06-06 10:49:17 -07:00
Debug - show traceback (use \fB -dd\fP for verbose traceback)
2021-07-19 12:08:50 -07:00
.TP
.B
2022-06-06 10:32:18 -07:00
\fB -h\fP , \fB --help\fP
2022-09-06 10:07:19 -07:00
Help (\fB --help --parser_name\fP for parser documentation). Use twice to show hidden parsers (e.g. \fB -hh\fP )
2021-07-19 12:08:50 -07:00
.TP
.B
2022-06-06 10:32:18 -07:00
\fB -m\fP , \fB --monochrome\fP
2022-06-06 10:49:17 -07:00
Monochrome output
2021-07-19 12:08:50 -07:00
.TP
.B
2022-08-21 12:38:55 -07:00
\fB -M\fP , \fB --meta-out\fP
Add metadata to output including timestamp, parser name, magic command, magic command exit code, etc.
.TP
.B
2022-06-06 10:32:18 -07:00
\fB -p\fP , \fB --pretty\fP
2022-06-06 10:49:17 -07:00
Pretty print output
2021-07-19 12:08:50 -07:00
.TP
.B
2022-06-06 10:32:18 -07:00
\fB -q\fP , \fB --quiet\fP
2022-06-06 10:49:17 -07:00
Quiet mode. Suppresses parser warning messages (use -qq to ignore streaming parser errors)
2021-07-19 12:08:50 -07:00
.TP
.B
2022-06-06 10:32:18 -07:00
\fB -r\fP , \fB --raw\fP
2022-06-06 10:49:17 -07:00
Raw output. Provides more literal output, typically with string values and no additional semantic processing
2021-07-19 12:08:50 -07:00
.TP
.B
2022-06-06 10:32:18 -07:00
\fB -u\fP , \fB --unbuffer\fP
2022-06-06 10:49:17 -07:00
Unbuffer output (useful for slow streaming data with streaming parsers)
2021-09-16 20:41:56 -07:00
.TP
.B
2022-06-06 10:32:18 -07:00
\fB -v\fP , \fB --version\fP
2022-06-06 10:49:17 -07:00
Version information
2022-05-23 13:43:57 -07:00
.TP
.B
2022-06-06 10:32:18 -07:00
\fB -y\fP , \fB --yaml-out\fP
2022-05-23 13:43:57 -07:00
YAML output
2022-06-05 17:40:05 -07:00
.TP
.B
2022-06-06 10:32:18 -07:00
\fB -B\fP , \fB --bash-comp\fP
2022-06-06 10:49:17 -07:00
Generate Bash shell completion script
2022-06-05 17:40:05 -07:00
.TP
.B
2022-06-06 10:32:18 -07:00
\fB -Z\fP , \fB --zsh-comp\fP
2022-06-06 10:49:17 -07:00
Generate Zsh shell completion script
2021-07-19 12:08:50 -07:00
.SH EXIT CODES
2022-08-24 09:24:03 -07:00
Any fatal errors within \fB jc\fP will generate an exit code of \fB 100\fP , otherwise the exit code will be \fB 0\fP .
When using the "magic" syntax (e.g. \fB jc ifconfig eth0\fP ), \fB jc\fP will store the exit code of the program being parsed and add it to the \fB jc\fP exit code. This way it is easier to determine if an error was from the parsed program or \fB jc\fP .
2021-07-19 12:08:50 -07:00
2021-12-08 11:21:12 -08:00
Consider the following examples using \fB ifconfig\fP :
2021-07-19 12:08:50 -07:00
.RS
ifconfig exit code = \fB 0\fP , jc exit code = \fB 0\fP , combined exit code = \fB 0\fP (no errors)
ifconfig exit code = \fB 1\fP , jc exit code = \fB 0\fP , combined exit code = \fB 1\fP (error in ifconfig)
ifconfig exit code = \fB 0\fP , jc exit code = \fB 100\fP , combined exit code = \fB 100\fP (error in jc)
ifconfig exit code = \fB 1\fP , jc exit code = \fB 100\fP , combined exit code = \fB 101\fP (error in both ifconfig and jc)
.RE
2022-08-24 09:24:03 -07:00
When using the "magic" syntax you can also retrieve the exit code of the called
program by using the \fB --meta-out\fP or \fB -M\fP option. This will append a \fB _jc_meta\fP
object to the output that will include the magic command information, including
the exit code.
Here is an example with \fB ping\fP :
.RS
.nf
$ jc --meta-out -p ping -c2 192.168.1.252
{
"destination_ip": "192.168.1.252",
"data_bytes": 56,
"pattern": null,
"destination": "192.168.1.252",
"packets_transmitted": 2,
"packets_received": 0,
"packet_loss_percent": 100.0,
"duplicates": 0,
"responses": [
{
"type": "timeout",
"icmp_seq": 0,
"duplicate": false
}
],
"_jc_meta": {
"parser": "ping",
"timestamp": 1661357115.27949,
"magic_command": [
"ping",
"-c2",
"192.168.1.252"
],
"magic_command_exit": 2
}
}
$ echo $?
2
.fi
.RE
2021-07-19 12:08:50 -07:00
.SH ENVIRONMENT
2021-12-08 08:35:09 -08:00
\fB Custom Colors\fP
2021-07-19 12:08:50 -07:00
You can specify custom colors via the \fB JC_COLORS\fP environment variable. The \fB JC_COLORS\fP 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: \fB black\fP , \fB red\fP , \fB green\fP , \fB yellow\fP , \fB blue\fP , \fB magenta\fP , \fB cyan\fP , \fB gray\fP , \fB brightblack\fP , \fB brightred\fP , \fB brightgreen\fP , \fB brightyellow\fP , \fB brightblue\fP , \fB brightmagenta\fP , \fB brightcyan\fP , \fB white\fP , or \fB default\fP
For example, to set to the default colors:
.RS
JC_COLORS=blue,brightblack,magenta,green
or
JC_COLORS=default,default,default,default
.RE
2021-12-08 08:35:09 -08:00
\fB Disable Color Output\fP
2022-05-12 11:16:44 -07:00
You can set the \fB NO_COLOR\fP environment variable to any value to disable color output in \fB jc\fP . Note that using the \fB -C\fP option to force color output will override both the \fB NO_COLOR\fP environment variable and the \fB -m\fP option.
2021-09-20 13:04:26 -07:00
.SH STREAMING PARSERS
2022-05-12 11:16:44 -07:00
Most parsers load all of the data from \fB STDIN\fP , parse it, then output the entire JSON document serially. There are some streaming parsers (e.g. \fB ls-s\fP , \fB ping-s\fP , etc.) that immediately start processing and outputing the data line-by-line as JSON Lines (aka NDJSON) while it is being received from \fB STDIN\fP . This can significantly reduce the amount of memory required to parse large amounts of command output (e.g. \fB ls -lR /\fP ) and can sometimes process the data more quickly. Streaming parsers have slightly different behavior than standard parsers as outlined below.
2021-09-20 13:04:26 -07:00
.RS
Note: Streaming parsers cannot be used with the "magic" syntax
.RE
\fB Ignoring Errors\fP
2021-09-23 13:08:31 -07:00
You may want to ignore parsing errors when using streaming parsers since these may be used in long-lived processing pipelines and errors can break the pipe. To ignore parsing errors, use the \fB -qq\fP cli option. This will add a \fB _jc_meta\fP object to the JSON output with a \fB success\fP attribute. If \fB success\fP is \fB true\fP , then there were no issues parsing the line. If \fB success\fP is \fB false\fP , then a parsing issue was found and \fB error\fP and \fB line\fP fields will be added to include a short error description and the contents of the unparsable line, respectively:
2021-09-20 13:04:26 -07:00
.RS
2021-09-23 11:54:58 -07:00
Successfully parsed line with \fB -qq\fP option:
2021-09-20 13:04:26 -07:00
.RS
2022-02-24 21:21:02 -08:00
.nf
2021-09-20 13:04:26 -07:00
{
"command_data": "data",
2021-09-23 13:08:31 -07:00
"_jc_meta": {
2021-09-20 13:04:26 -07:00
"success": true
}
}
2022-03-09 14:43:56 -08:00
.fi
2021-09-20 13:04:26 -07:00
.RE
2021-09-23 11:54:58 -07:00
Unsuccessfully parsed line with \fB -qq\fP option:
2021-09-20 13:04:26 -07:00
.RS
2022-02-24 21:21:02 -08:00
.nf
2021-09-20 13:04:26 -07:00
{
2021-09-23 13:08:31 -07:00
"_jc_meta": {
2021-09-20 13:04:26 -07:00
"success": false,
2021-09-23 12:58:24 -07:00
"error": "error message",
2021-09-20 13:04:26 -07:00
"line": "original line data"
}
}
2022-02-24 21:21:02 -08:00
.fi
2021-09-20 13:04:26 -07:00
.RE
.RE
\fB Unbuffering Output\fP
Most operating systems will buffer output that is being piped from process to process. The buffer is usually around 4KB. When viewing the output in the terminal the OS buffer is not engaged so output is immediately displayed on the screen. When piping multiple processes together, though, it may seem as if the output is hanging when the input data is very slow (e.g. \fB ping\fP ):
.RS
2022-02-24 21:21:02 -08:00
.nf
2022-03-09 14:17:48 -08:00
$ ping 1.1.1.1 | jc \fB --ping-s\fP | jq
2021-09-20 13:04:26 -07:00
<slow output>
2022-02-24 21:21:02 -08:00
.fi
2021-09-20 13:04:26 -07:00
.RE
This is because the OS engages the 4KB buffer between \fB jc\fP and \fB jq\fP in this example. To display the data on the terminal in realtime, you can disable the buffer with the \fB -u\fP (unbuffer) cli option:
.RS
2022-02-24 21:21:02 -08:00
.nf
2022-03-09 14:17:48 -08:00
$ ping 1.1.1.1 | jc \fB --ping-s\fP \fB -u\fP | jq
2022-02-24 21:21:02 -08:00
{"type":"reply","pattern":null,"timestamp":null,"bytes":"64",...}
{"type":"reply","pattern":null,"timestamp":null,"bytes":"64",...}
2021-09-20 13:04:26 -07:00
etc...
2022-02-24 21:21:02 -08:00
.fi
2021-09-20 13:04:26 -07:00
2021-09-23 08:53:25 -07:00
Note: Unbuffered output can be slower for large data streams.
2021-09-20 13:04:26 -07:00
.RE
2021-07-19 12:08:50 -07:00
.SH CUSTOM PARSERS
Custom local parser plugins may be placed in a \fB jc/jcparsers\fP folder in your local "App data directory":
.RS
2022-03-09 14:17:48 -08:00
.nf
2021-07-19 12:08:50 -07:00
- Linux/unix: \fB $HOME/.local/share/jc/jcparsers\fP
- macOS: \fB $HOME/Library/Application Support/jc/jcparsers\fP
- Windows: \fB $LOCALAPPDATA\\ jc\\ jc\\ jcparsers\fP
2022-03-09 14:17:48 -08:00
.fi
2021-07-19 12:08:50 -07:00
.RE
2022-05-12 11:16:44 -07:00
Local parser plugins are standard python module files. Use the \fB jc/parsers/foo.py\fP or \fB jc/parsers/foo_s.py\fP (streaming) parser as a template and simply place a \fB .py\fP file in the \fB jcparsers\fP subfolder.
2021-07-19 12:08:50 -07:00
2022-04-29 06:50:37 -07:00
Local plugin filenames must be valid python module names and therefore must start with a letter and consist entirely of alphanumerics and underscores. Local plugins may override default parsers.
2021-07-19 12:08:50 -07:00
Note: The application data directory follows the XDG Base Directory Specification
.SH CAVEATS
2022-05-12 11:16:44 -07:00
\fB Locale\fP
2022-07-30 12:23:43 -07:00
For best results set the locale environment variables to \fB C\fP or
\fB en_US.UTF-8\fP by modifying the \fB LC_ALL\fP variable:
2021-07-19 12:08:50 -07:00
2022-03-09 14:17:48 -08:00
.RS
2022-07-30 12:23:43 -07:00
$ LC_ALL=C date | jc \fB --date\fP
2022-03-09 14:17:48 -08:00
.RE
2021-07-19 12:08:50 -07:00
2022-07-30 12:23:43 -07:00
You can also set the locale variables individually:
2021-07-19 12:08:50 -07:00
2022-03-09 14:17:48 -08:00
.RS
$ export LANG=C
2022-07-30 12:23:43 -07:00
$ export LC_NUMERIC=C
2022-03-09 14:17:48 -08:00
.RE
2021-07-19 12:08:50 -07:00
2022-07-30 12:23:43 -07:00
On some older systems UTF-8 output will be downgraded to ASCII with \fB \\ u\fP
escape sequences if the \fB C\fP locale does not support UTF-8 encoding.
2022-05-12 11:16:44 -07:00
\fB Timezones\fP
2022-04-26 17:51:30 -07:00
2022-05-12 11:16:44 -07:00
Some parsers have calculated epoch timestamp fields added to the output. Unless a timestamp field name has a \fB _utc\fP suffix it is considered naive. (i.e. based on the local timezone of the system the \fB jc\fP parser was run on).
2021-07-19 12:08:50 -07:00
If a UTC timezone can be detected in the text of the command output, the timestamp will be timezone aware and have a \fB _utc\fP suffix on the key name. (e.g. \fB epoch_utc\fP ) No other timezones are supported for aware timestamps.
.SH EXAMPLES
Standard Syntax:
.RS
2022-09-07 13:56:16 -07:00
$ dig www.google.com | jc \fB -p\fP \fB --dig\fP
$ cat /proc/meminfo | jc \fB --pretty\fP \fB --proc\fP
2021-07-19 12:08:50 -07:00
.RE
Magic Syntax:
.RS
2022-09-07 13:56:16 -07:00
$ jc \fB --pretty\fP dig www.google.com
$ jc \fB --pretty\fP /proc/meminfo
2021-07-19 12:08:50 -07:00
.RE
For parser documentation:
.RS
2022-09-07 13:56:16 -07:00
$ jc \fB --help\fP \fB --dig\fP
2021-07-19 12:08:50 -07:00
.RE
.SH AUTHOR
Kelly Brazil (kellyjonbrazil@gmail.com)
https://github.com/kellyjonbrazil/jc
.SH COPYRIGHT
2022-01-02 11:07:15 -08:00
Copyright (c) 2019-2022 Kelly Brazil
2021-07-19 12:08:50 -07:00
License: MIT License