LinuxCommandLibrary

jq

command-line JSON processor

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 lightweight, command-line JSON processor often described as "sed for JSON." It reads JSON input from files or standard input, applies a filter expression, and writes the transformed result to standard output. Filters can be chained together with the pipe operator (`|`), enabling multi-step transformations that extract fields, restructure objects, compute values, and aggregate arrays in a single invocation.
The filter language supports object and array indexing (`.foo`, `.[0]`), iteration (`.[]`), conditionals (`if-then-else`), comparison and logic operators, built-in functions like `map`, `select`, `groupby`, and `sortby`, as well as string interpolation and regular expressions. This makes jq well suited for tasks like extracting nested values from API responses, converting JSON records into CSV, or reshaping data for downstream tools. Output can be pretty-printed (the default), compacted with `-c` for piping, or emitted as raw strings with `-r` for shell integration.

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)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community