.TH jc 1 2023-01-11 1.22.5 "JSON Convert" .SH NAME \fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types, and strings .SH SYNOPSIS Standard syntax: .RS COMMAND | \fBjc\fP [OPTIONS] PARSER cat FILE | \fBjc\fP [OPTIONS] PARSER echo STRING | \fBjc\fP [OPTIONS] PARSER .RE Magic syntax: .RS \fBjc\fP [OPTIONS] COMMAND \fBjc\fP [OPTIONS] /proc/ .RE .SH DESCRIPTION \fBjc\fP JSONifies the output of many CLI tools, file-types, and common strings for easier parsing in scripts. \fBjc\fP accepts piped input from \fBSTDIN\fP and outputs a JSON representation of the previous command's output to \fBSTDOUT\fP. Alternatively, the "Magic" syntax can be used by prepending \fBjc\fP to the command to be converted. Options can be passed to \fBjc\fP immediately before the command is given. (Note: "Magic" syntax does not support shell builtins or command aliases) .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 .TP .B \fB--asciitable\fP ASCII and Unicode table parser .TP .B \fB--asciitable-m\fP multi-line ASCII and Unicode table parser .TP .B \fB--blkid\fP `blkid` command parser .TP .B \fB--cbt\fP `cbt` (Google Bigtable) command parser .TP .B \fB--cef\fP CEF string parser .TP .B \fB--cef-s\fP CEF string streaming parser .TP .B \fB--chage\fP `chage --list` command parser .TP .B \fB--cksum\fP `cksum` and `sum` command parser .TP .B \fB--clf\fP Common and Combined Log Format file parser .TP .B \fB--clf-s\fP Common and Combined Log Format file streaming 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 .TP .B \fB--csv-s\fP CSV file streaming parser .TP .B \fB--date\fP `date` command parser .TP .B \fB--datetime-iso\fP ISO 8601 Datetime string 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 .TP .B \fB--email-address\fP Email Address string parser .TP .B \fB--env\fP `env` command parser .TP .B \fB--file\fP `file` command parser .TP .B \fB--findmnt\fP `findmnt` 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 .TP .B \fB--git-log\fP `git log` command parser .TP .B \fB--git-log-s\fP `git log` command streaming parser .TP .B \fB--git-ls-remote\fP `git ls-remote` command parser .TP .B \fB--gpg\fP `gpg --with-colons` command parser .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 .TP .B \fB--ini-dup\fP INI with duplicate key file parser .TP .B \fB--iostat\fP `iostat` command parser .TP .B \fB--iostat-s\fP `iostat` command streaming parser .TP .B \fB--ip-address\fP IPv4 and IPv6 Address string parser .TP .B \fB--iptables\fP `iptables` command parser .TP .B \fB--iso-datetime\fP Deprecated - please use datetime-iso .TP .B \fB--iw-scan\fP `iw dev [device] scan` command parser .TP .B \fB--iwconfig\fP `iwconfig` command parser .TP .B \fB--jar-manifest\fP Java MANIFEST.MF file parser .TP .B \fB--jobs\fP `jobs` command parser .TP .B \fB--jwt\fP JWT string parser .TP .B \fB--kv\fP Key/Value file and string parser .TP .B \fB--last\fP `last` and `lastb` command parser .TP .B \fB--ls\fP `ls` command parser .TP .B \fB--ls-s\fP `ls` command streaming parser .TP .B \fB--lsblk\fP `lsblk` command parser .TP .B \fB--lsmod\fP `lsmod` command parser .TP .B \fB--lsof\fP `lsof` command parser .TP .B \fB--lspci\fP `lspci -mmv` command parser .TP .B \fB--lsusb\fP `lsusb` command parser .TP .B \fB--m3u\fP M3U and M3U8 file parser .TP .B \fB--mdadm\fP `mdadm` command parser .TP .B \fB--mount\fP `mount` command parser .TP .B \fB--mpstat\fP `mpstat` command parser .TP .B \fB--mpstat-s\fP `mpstat` command streaming parser .TP .B \fB--netstat\fP `netstat` command parser .TP .B \fB--nmcli\fP `nmcli` command parser .TP .B \fB--ntpq\fP `ntpq -p` command parser .TP .B \fB--openvpn\fP openvpn-status.log file parser .TP .B \fB--os-prober\fP `os-prober` command parser .TP .B \fB--passwd\fP `/etc/passwd` file parser .TP .B \fB--pci-ids\fP `pci.ids` file parser .TP .B \fB--pgpass\fP PostgreSQL password file parser .TP .B \fB--pidstat\fP `pidstat -H` command parser .TP .B \fB--pidstat-s\fP `pidstat -H` command streaming parser .TP .B \fB--ping\fP `ping` and `ping6` command parser .TP .B \fB--ping-s\fP `ping` and `ping6` command streaming parser .TP .B \fB--pip-list\fP `pip list` command parser .TP .B \fB--pip-show\fP `pip show` command parser .TP .B \fB--plist\fP PLIST file parser .TP .B \fB--postconf\fP `postconf -M` command parser .TP .B \fB--proc\fP `/proc/` file parser .TP .B \fB--proc-buddyinfo\fP `/proc/buddyinfo` file parser .TP .B \fB--proc-consoles\fP `/proc/consoles` file parser .TP .B \fB--proc-cpuinfo\fP `/proc/cpuinfo` file parser .TP .B \fB--proc-crypto\fP `/proc/crypto` file parser .TP .B \fB--proc-devices\fP `/proc/devices` file parser .TP .B \fB--proc-diskstats\fP `/proc/diskstats` file parser .TP .B \fB--proc-filesystems\fP `/proc/filesystems` file parser .TP .B \fB--proc-interrupts\fP `/proc/interrupts` file parser .TP .B \fB--proc-iomem\fP `/proc/iomem` file parser .TP .B \fB--proc-ioports\fP `/proc/ioports` file parser .TP .B \fB--proc-loadavg\fP `/proc/loadavg` file parser .TP .B \fB--proc-locks\fP `/proc/locks` file parser .TP .B \fB--proc-meminfo\fP `/proc/meminfo` file parser .TP .B \fB--proc-modules\fP `/proc/modules` file parser .TP .B \fB--proc-mtrr\fP `/proc/mtrr` file parser .TP .B \fB--proc-pagetypeinfo\fP `/proc/pagetypeinfo` file parser .TP .B \fB--proc-partitions\fP `/proc/partitions` file parser .TP .B \fB--proc-slabinfo\fP `/proc/slabinfo` file parser .TP .B \fB--proc-softirqs\fP `/proc/softirqs` file parser .TP .B \fB--proc-stat\fP `/proc/stat` file parser .TP .B \fB--proc-swaps\fP `/proc/swaps` file parser .TP .B \fB--proc-uptime\fP `/proc/uptime` file parser .TP .B \fB--proc-version\fP `/proc/version` file parser .TP .B \fB--proc-vmallocinfo\fP `/proc/vmallocinfo` file parser .TP .B \fB--proc-vmstat\fP `/proc/vmstat` file parser .TP .B \fB--proc-zoneinfo\fP `/proc/zoneinfo` file parser .TP .B \fB--proc-driver-rtc\fP `/proc/driver/rtc` file parser .TP .B \fB--proc-net-arp\fP `/proc/net/arp` file parser .TP .B \fB--proc-net-dev\fP `/proc/net/dev` file parser .TP .B \fB--proc-net-dev-mcast\fP `/proc/net/dev_mcast` file parser .TP .B \fB--proc-net-if-inet6\fP `/proc/net/if_inet6` file parser .TP .B \fB--proc-net-igmp\fP `/proc/net/igmp` file parser .TP .B \fB--proc-net-igmp6\fP `/proc/net/igmp6` file parser .TP .B \fB--proc-net-ipv6-route\fP `/proc/net/ipv6_route` file parser .TP .B \fB--proc-net-netlink\fP `/proc/net/netlink` file parser .TP .B \fB--proc-net-netstat\fP `/proc/net/netstat` file parser .TP .B \fB--proc-net-packet\fP `/proc/net/packet` file parser .TP .B \fB--proc-net-protocols\fP `/proc/net/protocols` file parser .TP .B \fB--proc-net-route\fP `/proc/net/route` file parser .TP .B \fB--proc-net-unix\fP `/proc/net/unix` file parser .TP .B \fB--proc-pid-fdinfo\fP `/proc//fdinfo/` file parser .TP .B \fB--proc-pid-io\fP `/proc//io` file parser .TP .B \fB--proc-pid-maps\fP `/proc//maps` file parser .TP .B \fB--proc-pid-mountinfo\fP `/proc//mountinfo` file parser .TP .B \fB--proc-pid-numa-maps\fP `/proc//numa_maps` file parser .TP .B \fB--proc-pid-smaps\fP `/proc//smaps` file parser .TP .B \fB--proc-pid-stat\fP `/proc//stat` file parser .TP .B \fB--proc-pid-statm\fP `/proc//statm` file parser .TP .B \fB--proc-pid-status\fP `/proc//status` file parser .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 .TP .B \fB--rsync\fP `rsync` command parser .TP .B \fB--rsync-s\fP `rsync` command streaming parser .TP .B \fB--semver\fP Semantic Version string parser .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--sshd-conf\fP sshd config file and `sshd -T` command parser .TP .B \fB--stat\fP `stat` command parser .TP .B \fB--stat-s\fP `stat` command streaming parser .TP .B \fB--sysctl\fP `sysctl` command parser .TP .B \fB--syslog\fP Syslog RFC 5424 string parser .TP .B \fB--syslog-s\fP Syslog RFC 5424 string streaming parser .TP .B \fB--syslog-bsd\fP Syslog RFC 3164 string parser .TP .B \fB--syslog-bsd-s\fP Syslog RFC 3164 string streaming parser .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 .TP .B \fB--timestamp\fP Unix Epoch Timestamp string parser .TP .B \fB--toml\fP TOML file parser .TP .B \fB--top\fP `top -b` command parser .TP .B \fB--top-s\fP `top -b` command streaming parser .TP .B \fB--tracepath\fP `tracepath` and `tracepath6` command parser .TP .B \fB--traceroute\fP `traceroute` and `traceroute6` command parser .TP .B \fB--udevadm\fP `udevadm info` 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 .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 .TP .B \fB--upower\fP `upower` command parser .TP .B \fB--uptime\fP `uptime` command parser .TP .B \fB--url\fP URL string parser .TP .B \fB--vmstat\fP `vmstat` command parser .TP .B \fB--vmstat-s\fP `vmstat` command streaming parser .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 \fB--x509-cert\fP X.509 PEM and DER certificate file parser .TP .B \fB--xml\fP XML file parser .TP .B \fB--xrandr\fP `xrandr` command parser .TP .B \fB--yaml\fP YAML file parser .TP .B \fB--zipinfo\fP `zipinfo` command parser .RE .PP .B Options: .RS .TP .B \fB-a\fP, \fB--about\fP About \fBjc\fP (JSON or YAML output) .TP .B \fB-C\fP, \fB--force-color\fP Force color output even when using pipes (overrides \fB-m\fP and the \fBNO_COLOR\fP env variable) .TP .B \fB-d\fP, \fB--debug\fP Debug - show traceback (use \fB-dd\fP for verbose traceback) .TP .B \fB-h\fP, \fB--help\fP Help (\fB--help --parser_name\fP for parser documentation). Use twice to show hidden parsers (e.g. \fB-hh\fP) .TP .B \fB-m\fP, \fB--monochrome\fP Monochrome output .TP .B \fB-M\fP, \fB--meta-out\fP Add metadata to output including timestamp, parser name, magic command, magic command exit code, etc. .TP .B \fB-p\fP, \fB--pretty\fP Pretty print output .TP .B \fB-q\fP, \fB--quiet\fP Quiet mode. Suppresses parser warning messages (use -qq to ignore streaming parser errors) .TP .B \fB-r\fP, \fB--raw\fP Raw output. Provides more literal output, typically with string values and no additional semantic processing .TP .B \fB-u\fP, \fB--unbuffer\fP Unbuffer output (useful for slow streaming data with streaming parsers) .TP .B \fB-v\fP, \fB--version\fP Version information .TP .B \fB-y\fP, \fB--yaml-out\fP YAML output .TP .B \fB-B\fP, \fB--bash-comp\fP Generate Bash shell completion script .TP .B \fB-Z\fP, \fB--zsh-comp\fP Generate Zsh shell completion script .SH EXIT CODES Any fatal errors within \fBjc\fP will generate an exit code of \fB100\fP, otherwise the exit code will be \fB0\fP. When using the "magic" syntax (e.g. \fBjc ifconfig eth0\fP), \fBjc\fP will store the exit code of the program being parsed and add it to the \fBjc\fP exit code. This way it is easier to determine if an error was from the parsed program or \fBjc\fP. Consider the following examples using \fBifconfig\fP: .RS ifconfig exit code = \fB0\fP, jc exit code = \fB0\fP, combined exit code = \fB0\fP (no errors) ifconfig exit code = \fB1\fP, jc exit code = \fB0\fP, combined exit code = \fB1\fP (error in ifconfig) ifconfig exit code = \fB0\fP, jc exit code = \fB100\fP, combined exit code = \fB100\fP (error in jc) ifconfig exit code = \fB1\fP, jc exit code = \fB100\fP, combined exit code = \fB101\fP (error in both ifconfig and jc) .RE 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 \fBping\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 .SH ENVIRONMENT \fBCustom Colors\fP You can specify custom colors via the \fBJC_COLORS\fP environment variable. The \fBJC_COLORS\fP environment variable takes four comma separated string values in the following format: JC_COLORS=,,, Where colors are: \fBblack\fP, \fBred\fP, \fBgreen\fP, \fByellow\fP, \fBblue\fP, \fBmagenta\fP, \fBcyan\fP, \fBgray\fP, \fBbrightblack\fP, \fBbrightred\fP, \fBbrightgreen\fP, \fBbrightyellow\fP, \fBbrightblue\fP, \fBbrightmagenta\fP, \fBbrightcyan\fP, \fBwhite\fP, or \fBdefault\fP For example, to set to the default colors: .RS JC_COLORS=blue,brightblack,magenta,green or JC_COLORS=default,default,default,default .RE \fBDisable Color Output\fP You can set the \fBNO_COLOR\fP environment variable to any value to disable color output in \fBjc\fP. Note that using the \fB-C\fP option to force color output will override both the \fBNO_COLOR\fP environment variable and the \fB-m\fP option. .SH STREAMING PARSERS Most parsers load all of the data from \fBSTDIN\fP, parse it, then output the entire JSON document serially. There are some streaming parsers (e.g. \fBls-s\fP, \fBping-s\fP, etc.) that immediately start processing and outputting the data line-by-line as JSON Lines (aka NDJSON) while it is being received from \fBSTDIN\fP. This can significantly reduce the amount of memory required to parse large amounts of command output (e.g. \fBls -lR /\fP) and can sometimes process the data more quickly. Streaming parsers have slightly different behavior than standard parsers as outlined below. .RS Note: Streaming parsers cannot be used with the "magic" syntax .RE \fBIgnoring Errors\fP 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 \fBsuccess\fP attribute. If \fBsuccess\fP is \fBtrue\fP, then there were no issues parsing the line. If \fBsuccess\fP is \fBfalse\fP, then a parsing issue was found and \fBerror\fP and \fBline\fP fields will be added to include a short error description and the contents of the unparsable line, respectively: .RS Successfully parsed line with \fB-qq\fP option: .RS .nf { "command_data": "data", "_jc_meta": { "success": true } } .fi .RE Unsuccessfully parsed line with \fB-qq\fP option: .RS .nf { "_jc_meta": { "success": false, "error": "error message", "line": "original line data" } } .fi .RE .RE \fBUnbuffering 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. \fBping\fP): .RS .nf $ ping 1.1.1.1 | jc \fB--ping-s\fP | jq .fi .RE This is because the OS engages the 4KB buffer between \fBjc\fP and \fBjq\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 .nf $ ping 1.1.1.1 | jc \fB--ping-s\fP \fB-u\fP | jq {"type":"reply","pattern":null,"timestamp":null,"bytes":"64",...} {"type":"reply","pattern":null,"timestamp":null,"bytes":"64",...} etc... .fi Note: Unbuffered output can be slower for large data streams. .RE .SH CUSTOM PARSERS Custom local parser plugins may be placed in a \fBjc/jcparsers\fP folder in your local "App data directory": .RS .nf - 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 .fi .RE Local parser plugins are standard python module files. Use the \fBjc/parsers/foo.py\fP or \fBjc/parsers/foo_s.py\fP (streaming) parser as a template and simply place a \fB.py\fP file in the \fBjcparsers\fP subfolder. 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. Note: The application data directory follows the XDG Base Directory Specification .SH CAVEATS \fBLocale\fP For best results set the locale environment variables to \fBC\fP or \fBen_US.UTF-8\fP by modifying the \fBLC_ALL\fP variable: .RS $ LC_ALL=C date | jc \fB--date\fP .RE You can also set the locale variables individually: .RS $ export LANG=C $ export LC_NUMERIC=C .RE On some older systems UTF-8 output will be downgraded to ASCII with \fB\\u\fP escape sequences if the \fBC\fP locale does not support UTF-8 encoding. \fBTimezones\fP 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 \fBjc\fP 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 \fB_utc\fP suffix on the key name. (e.g. \fBepoch_utc\fP) No other timezones are supported for aware timestamps. .SH EXAMPLES Standard Syntax: .RS $ dig www.google.com | jc \fB-p\fP \fB--dig\fP $ cat /proc/meminfo | jc \fB--pretty\fP \fB--proc\fP .RE Magic Syntax: .RS $ jc \fB--pretty\fP dig www.google.com $ jc \fB--pretty\fP /proc/meminfo .RE For parser documentation: .RS $ jc \fB--help\fP \fB--dig\fP .RE .SH AUTHOR Kelly Brazil (kellyjonbrazil@gmail.com) https://github.com/kellyjonbrazil/jc .SH COPYRIGHT Copyright (c) 2019-2023 Kelly Brazil License: MIT License