JC - JSON from CLI

Page content

how to build json from cli

we all like json, do we ? https://kellyjonbrazil.github.io/jc/docs/parsers/ping

add package

doas pkg_add jc

try ping

openbsd-box # ping -c 3 1.1.1.1 |jc --ping -p 2>/dev/null
{
  "destination_ip": "1.1.1.1",
  "data_bytes": 56,
  "pattern": null,
  "destination": "1.1.1.1",
  "packets_transmitted": 3,
  "packets_received": 3,
  "packet_loss_percent": 0.0,
  "duplicates": 0,
  "round_trip_ms_min": 9.219,
  "round_trip_ms_avg": 9.826,
  "round_trip_ms_max": 10.158,
  "round_trip_ms_stddev": 0.43,
  "responses": [
    {
      "type": "reply",
      "bytes": 64,
      "response_ip": "1.1.1.1",
      "icmp_seq": 0,
      "ttl": 59,
      "time_ms": 10.158,
      "duplicate": false
    },
    {
      "type": "reply",
      "bytes": 64,
      "response_ip": "1.1.1.1",
      "icmp_seq": 1,
      "ttl": 59,
      "time_ms": 9.219,
      "duplicate": false
    },
    {
      "type": "reply",
      "bytes": 64,
      "response_ip": "1.1.1.1",
      "icmp_seq": 2,
      "ttl": 59,
      "time_ms": 10.101,
      "duplicate": false
    }
  ]
}

Compatible platforms: linux, darwin, freebsd -> had to redirect the stderr to /dev/null because OpenBSD is not (yet) supported officially…

Supported Commands

    --acpi              `acpi` command parser
    --airport           `airport -I` command parser
    --airport-s         `airport -s` command parser
    --arp               `arp` command parser
    --asciitable        ASCII and Unicode table parser
    --asciitable-m      multi-line ASCII and Unicode table parser
    --blkid             `blkid` command parser
    --chage             `chage --list` 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
    --csv-s             CSV file streaming 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
    --email-address     Email Address string parser
    --env               `env` command parser
    --file              `file` command parser
    --finger            `finger` command parser
    --free              `free` command parser
    --fstab             `/etc/fstab` file parser
    --git-log           `git log` command parser
    --git-log-s         `git log` command streaming parser
    --gpg               `gpg --with-colons` command 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
    --iostat            `iostat` command parser
    --iostat-s          `iostat` command streaming parser
    --iptables          `iptables` command parser
    --iso-datetime      ISO 8601 Datetime string parser
    --iw-scan           `iw dev [device] scan` command parser
    --jar-manifest      MANIFEST.MF file parser
    --jobs              `jobs` command parser
    --jwt               JWT string parser
    --kv                Key/Value file parser
    --last              `last` and `lastb` command parser
    --ls                `ls` command parser
    --ls-s              `ls` command streaming parser
    --lsblk             `lsblk` command parser
    --lsmod             `lsmod` command parser
    --lsof              `lsof` command parser
    --lsusb             `lsusb` command parser
    --m3u               M3U and M3U8 file parser
    --mount             `mount` command parser
    --mpstat            `mpstat` command parser
    --mpstat-s          `mpstat` command streaming parser
    --netstat           `netstat` command parser
    --nmcli             `nmcli` command parser
    --ntpq              `ntpq -p` command parser
    --passwd            `/etc/passwd` file parser
    --pidstat           `pidstat -h` command parser
    --pidstat-s         `pidstat -h` command streaming parser
    --ping              `ping` and `ping6` command parser
    --ping-s            `ping` and `ping6` command streaming parser
    --pip-list          `pip list` command parser
    --pip-show          `pip show` command parser
    --postconf          `postconf -M` command parser
    --ps                `ps` command parser
    --route             `route` command parser
    --rpm-qi            `rpm -qi` command parser
    --rsync             `rsync` command parser
    --rsync-s           `rsync` command streaming parser
    --sfdisk            `sfdisk` command parser
    --shadow            `/etc/shadow` file parser
    --ss                `ss` command parser
    --stat              `stat` command parser
    --stat-s            `stat` command streaming 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
    --timestamp         UNIX Epoch Timestamp string parser
    --top               `top -b` command parser
    --top-s             `top -b` command streaming 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
    --update-alt-gs     `update-alternatives --get-selections` command parser
    --update-alt-q      `update-alternatives --query` command parser
    --upower            `upower` command parser
    --uptime            `uptime` command parser
    --url               URL string parser
    --vmstat            `vmstat` command parser
    --vmstat-s          `vmstat` command streaming parser
    --w                 `w` command parser
    --wc                `wc` command parser
    --who               `who` command parser
    --x509-cert         X.509 PEM and DER certificate file parser
    --xml               XML file parser
    --xrandr            `xrandr` command parser
    --yaml              YAML file parser
    --zipinfo           `zipinfo` command parser

Any Comments ?

sha256: 4cc7076dbdc94336510813dfd535bc1341a2d5a4061b62c22df78c6e8fac1bfc