Parsers

On this page

jz list prints the table below from the binary you have. jz list df shows the variants of one command and jz list df gnu everything about one definition, including where it came from and how it detects its input.

Supported commands #

CommandVariants
aptlist
blkidlinux
bluetoothctlshow
cargocommand-list
cksumposix
dfbsd, bsd-human, busybox-human, gnu, gnu-human, gnu-inodes, gnu-inodes-human, gnu-type, gnu-type-human
digbind
dpkglist
dugnu-human, posix
envnull-separated, posix
etcgroup, hosts, os-release, passwd
ethtooldriver-info
fdisklinux
fileposix
findmntdf, linux, source-first
freegnu, gnu-human, gnu-wide
getconfglibc
gitbranch-verbose, config-list, log-oneline, remote-verbose, stash-list, status-porcelain
goenv
hostbind
hostnamectllinux
idposix
iostatcpu, device, linux
ipbrief-address, brief-link, neighbour, route, stats-link
iwlink
journalctlboots, short, short-iso, short-precise
localeposix
localectllinux
loginctlseats, sessions, users
losetuplinux
lslong, long-context, long-inode, long-no-owner-group
lsattrlinux
lsb_releaselinux
lsblkbytes, filesystems, linux, pairs, topology
lscpulinux
lsipclinux
lslockslinux
lsloginslinux
lsmemlinux
lsmodbusybox, linux
lsnslinux
lsoflinux
lspcikernel, linux, machine, numeric, numeric-names, verbose-machine
lsusblinux
md5sumposix
misels
mountbsd, linux
mpstatlinux
nmcliconnection, device
npmls, outdated
partedmachine
pidstatlinux
pinglinux
pipcolumns
psbsd, busybox, posix, unix
rfkilllinux, list
sensorslinux
sfdiskdump
sha256sumposix
sslinux
statgnu, gnu-filesystem, gnu-terse
swaponlegacy, linux
sysctllinux
systemctlshow, sockets, timers, unit-files, units
systemd-analyzeblame
tarbusybox, gnu
timedatectllinux, timesync, timezones
toplinux
tracepathlinux
ulimitbash, dash
unamedarwin, linux
unzipbusybox, info-zip
upowerdevice, dump, enumerate
uptimebsd, linux
vmstatlinux, linux-active, linux-disk, linux-disk-summary, linux-stats
wbsd, linux, linux-short
wcposix
whoposix
xrandrlinux, listmonitors
zipinfodefault

A variant is one output format of a command. GNU df, df -h, macOS df and BusyBox df -h are four formats, so they are four definitions. When several implementations print the same format, one definition covers them and says so in its metadata.

How a definition is chosen #

Every definition carries a signature: the shape its output has.

detect:
  os: [linux]
  args: {any: ["-h"], none: ["-i"]}
  signature:
    all: ['^Filesystem\s+Size\s+Used\s+Avail\s+Use%\s+Mounted on\s*$']

The signature is a necessary condition. The operating system and the arguments are known only when jz ran the command itself; they can then remove candidates, never promote one. Exactly one survivor is a success. Zero and more than one are errors that say what to pass.

Some formats are not evidence of anything. A number, a tab and a path describes du output and git diff --numstat alike, and three numbers in a row describe almost any table. Such a definition sets auto_detect: false: it stays out of automatic detection and is used when you name it, where its signature is still checked.

What jz will not invent #

A rounded, human-readable number reaches JSON exactly as printed. The base behind a suffix is not in the output (df -h steps by 1024, df -H by 1000) and the value is rounded either way, so a byte count would be two guesses stacked. Ask the command for exact numbers when you need them: df, free, lsblk -b.

Where the exact and the rounded form of a command are separate definitions, the exact one gives numbers: df does, df -h does not. That split needs the two forms to be told apart, and telling them apart means reading the values, which jz only sees for the first 200 lines. A listing has no length limit, so ls -l and ls -lh are one definition and its size is a string in both. The rule is the same one; what changes is whether jz can know which form it has.

The same reasoning applies to env: a value containing a newline cannot be told from two variables in the line-based output, so env -0 | jz exists for the cases where that matters.

NAME=value is also what a .env file, a properties file and a shell fragment look like, so the line-based form is one of the definitions jz will not claim on sight. env | jz --parser env and jz run env read it; env -0 is distinctive and needs no name.