JSON from command output, files and arguments, for the next command

jsonize makes JSON for the next command. jz turns what a command printed, a CSV, YAML or text file, or the arguments of a script into JSON and hands it on, to jq, curl or a CI step. When the input is not what it should be, jz says so and prints nothing, so the next command never reads a guess.

jz reading df, uptime and free, and refusing input it cannot identify

Try it in 30 seconds #

$ df -h | go run github.com/nao1215/jsonize/cmd/jz@latest
[{"filesystem":"/dev/nvme0n1p2","size":"1.8T","used":"1.6T","available":"145G","use_percent":92,"mounted_on":"/"}, ...]

A size rounded by -h stays the string df printed, and use_percent is a number.

Three things to try next #

$ jz run --pretty free
$ jz --file users.csv --type id=int
$ jz new --string "message=$MESSAGE" --path /metadata/labels/app=api replicas:=3

Why jsonize? #

You wantUse
JSON from a command that has no --json optionCOMMAND | jz or jz run COMMAND
a CSV, TSV, LTSV, JSON Lines or YAML file as JSONjz --file FILE
lines, or the names find -print0 prints, as a JSON arrayCOMMAND | jz --format lines (or nul)
a JSON body built in a shell scriptjz new key=value key:=json
every record of a stream wrapped with the fields a consumer needsjz --stream | jz new --each host=web sample:=@-
to select, sort or reshape JSON you already havejq
a parser for a command jz does not know yeta YAML definition in your own registry

jz reads 280 commands through 758 definitions, from df, ps and ip to kubectl get, docker ps, tasklist and diskutil list, on Linux, macOS, Windows and FreeBSD. A definition is a YAML file with captured output beside it; no Go code is needed to add one.

Data files and text #

A file is read as the format its extension names, and piped data as the format --format names. Nothing is detected, a CSV column stays text unless --type names its type, and text the format does not allow is exit 3 with the line. --format lines and nul read plain text as a list of strings.

jz reading a CSV file and a YAML file

JSON from arguments #

jz new builds a document from key=value (a string), key:=json (any JSON value), key=@file (a file’s text) and key[]=value (an array). --string passes text that must not be read as a file name, --path places a value at a JSON Pointer, and --each makes one document per line of standard input. Nothing is guessed from a value.

jz new building objects and an array

Install #

go install github.com/nao1215/jsonize/cmd/jz@latest

Homebrew, release archives, Linux packages and shell completion are on the install page.

Where to go #