jq
Syntax for filtering, mapping and restructuring JSON data from the command line.
Basic Filters
Essential commands to extract and manipulate JSON values.
Extract a key's value
Selects the value of a specific key in a JSON object.
jq '.key'Pretty-print JSON
Formats JSON with indentation for better readability.
jq '.'Filtering and Transforming
Methods to search, modify, and transform JSON data.
Select objects with a condition
Filters objects based on a condition.
jq 'select(.age > 18)'Map over an array
Applies a function to each element in an array.
jq 'map(.key)'Flatten nested arrays
Flattens an array of arrays into a single array.
jq 'flatten'Extract specific fields from objects in an array
Creates an array of selected fields from objects.
jq 'map({name: .name, age: .age})'Advanced Techniques
Powerful transformations using jq’s built-in functions.
Construct new JSON objects
Builds a new object with selected properties.
jq '{name: .name, age: .age}'String interpolation
Formats strings dynamically using variables.
jq '"Hello \(.name)!"'Group by a key
Groups objects in an array by a specific key.
jq 'group_by(.category)'Count occurrences of values
Counts occurrences of unique values in an array.
jq 'group_by(.) | map({key: .[0], count: length})'Convert JSON to CSV
Converts an array of objects into CSV format.
jq -r 'map([.name, .age] | @csv) | .[]'