LinuxCommandLibrary

jq

TLDR

Pretty print JSON

$ cat [data.json] | jq '.'
copy
Extract field
$ cat [data.json] | jq '.name'
copy
Array indexing
$ cat [data.json] | jq '.[0]'
copy
Filter array
$ cat [data.json] | jq '.[] | select(.age > 30)'
copy
Map transformation
$ cat [data.json] | jq '[.[] | {name, age}]'
copy
Raw string output
$ cat [data.json] | jq -r '.name'
copy
Compact output
$ cat [data.json] | jq -c '.'
copy

SYNOPSIS

jq [options] filter [file...]

DESCRIPTION

jq is a command-line JSON processor. It filters, transforms, and formats JSON data.
The tool uses a powerful query language for JSON manipulation. It supports complex transformations and data extraction.
jq processes and transforms JSON.

PARAMETERS

FILTER

jq filter expression.
FILE
Input JSON file(s).
-r, --raw-output
Output raw strings.
-c, --compact-output
Compact output.
-s, --slurp
Read entire input as array.
-n, --null-input
No input.
--arg NAME VAL
Set variable.
--help
Display help information.

CAVEATS

Learning curve for complex queries. Streaming mode for large files. Null handling can be tricky.

HISTORY

jq was created by Stephen Dolan as a sed/awk equivalent for JSON, becoming the standard CLI JSON tool.

SEE ALSO

jo(1), jc(1), yq(1), gron(1)

Copied to clipboard