jq – JSON Processor

jq is a lightweight command-line JSON processor. It slices, filters, maps, and transforms structured data...

Terminal Tools Linux Open Source
Download

jq is a lightweight command-line JSON processor. It slices, filters, maps, and transforms structured data with the same ease that sed, awk, and grep handle text.

Key Features

  • Filter Language: Powerful JSON query syntax
  • Transformation: Reshape JSON data
  • Stream Processing: Handle large files
  • Pretty Print: Format JSON output
  • Zero Dependencies: Single binary

Installation

Install jq on Ubuntu:

sudo apt install jq

Usage Examples

Common jq operations:

# Pretty print
curl api.example.com/data | jq .

# Extract field
echo '{"name":"John","age":30}' | jq .name

# Filter array
echo '[{"id":1},{"id":2},{"id":3}]' | jq '.[] | select(.id > 1)'

# Transform data
echo '[{"name":"John"},{"name":"Jane"}]' | jq '[.[] | .name]'

# Multiple operations
cat data.json | jq '
  .items
  | map(select(.active))
  | sort_by(.date)
  | .[0:5]
'

Benefits

jq makes JSON manipulation trivial on the command line. Its powerful query language handles complex transformations that would require writing code in other contexts.

Download jq

Was this article helpful?