jq

Slice, filter and reshape JSON from the terminal

About

A small query language for JSON. It turns tangled documents into exactly the fields you want. It filters, maps, orders and reformats, and can pretty-print or minify.

Install it

pkg install jq

Run this inside Termux. If the package is already present, pkg will say so and do nothing.

Commands worth knowing

6 of the invocations you will actually reach for. Tap the copy button to put one on your clipboard.

jq . payload.json Pretty-print a compact document with consistent indentation.
jq .items[].name data.json Extract one field from every element of an array.
jq -r .version package.json Print a value as raw text, without surrounding quotes.
jq .[] | select(.price > 100) catalog.json Keep only the objects whose numeric field exceeds a threshold.
jq -c . data.json Emit compact output on a single line, the opposite of pretty-printing.
jq keys data.json List the top-level field names of an object.

Worked example

Run jq .items[].name data.json and this is what you should see.

termux
$ jq .items[].name data.json
widget
sprocket
cog

Developed by

Stephen Dolan .