$linuxjunkies
>

jq(1)

Parse, filter, and transform JSON data from the command line.

UbuntuDebianFedoraArch

Synopsis

jq [OPTION]... FILTER [FILE]...

Description

jq is a lightweight command-line JSON processor that uses a powerful filter language to extract, transform, and manipulate JSON structures. It reads JSON input from files or standard input and outputs the filtered results.

The filter syntax supports object/array indexing, recursive descent, pipes, conditionals, loops, variable bindings, and function definitions—making it possible to perform complex data transformations without writing a program.

Common options

FlagWhat it does
-rraw output: output plain text strings without JSON quotes
-sslurp: read entire input into a single array and process it
-Rraw input: treat each line of input as a string instead of JSON
-ccompact output: single-line JSON with no unnecessary whitespace
-nnull input: don't read input, useful for generating data
-eset exit status based on output (0 if truthy/non-empty)
-jno newlines: suppress the trailing newline on output
-Mmonochrome output: disable colored syntax highlighting
--arg name valueset variable $name to string value in filter
--argjson name jsonset variable $name to parsed JSON value

Examples

Extract the name field from a JSON object

echo '{"name": "Alice", "age": 30}' | jq '.name'

Filter array elements where age is greater than 25

jq '.[] | select(.age > 25)' people.json

Format and output raw text using string interpolation

jq -r '.[] | "\(.name) is \(.age)"' people.json

Fetch JSON from API and extract specific fields

curl https://api.example.com/users | jq '.data[] | {id, email}'

Read entire file, group by category, and count items in each group

jq -s 'group_by(.category) | map({category: .[0].category, count: length})' data.json

Generate JSON from command-line arguments without reading input

jq -n --arg user alice --argjson count 42 '{user: $user, count: $count}'

List all keys from each object in an array

jq '.[] | keys' objects.json

Filter object entries by value and reconstruct the object

jq 'to_entries | map(select(.value > 10)) | from_entries' config.json

Related commands