jq(1)
Parse, filter, and transform JSON data from the command line.
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
| Flag | What it does |
|---|---|
-r | raw output: output plain text strings without JSON quotes |
-s | slurp: read entire input into a single array and process it |
-R | raw input: treat each line of input as a string instead of JSON |
-c | compact output: single-line JSON with no unnecessary whitespace |
-n | null input: don't read input, useful for generating data |
-e | set exit status based on output (0 if truthy/non-empty) |
-j | no newlines: suppress the trailing newline on output |
-M | monochrome output: disable colored syntax highlighting |
--arg name value | set variable $name to string value in filter |
--argjson name json | set 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.jsonFormat and output raw text using string interpolation
jq -r '.[] | "\(.name) is \(.age)"' people.jsonFetch 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.jsonGenerate 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.jsonFilter object entries by value and reconstruct the object
jq 'to_entries | map(select(.value > 10)) | from_entries' config.json