Overview
jq takes JSON data as input and processes and outputs it in various ways. It can perform anything from simple value extraction to complex array/object manipulation, making it an essential tool for handling JSON in scripting environments.
Key Features
- Parsing and formatting JSON data
- Extracting and filtering specific fields
- Manipulating arrays and objects
- Transforming and restructuring data
Key Options
Input/Output Formats
Filtering/Transformation
Generated command:
Try combining the commands.
Description:
`jq` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Examples
Basic JSON Formatting
echo '{"name": "Alice", "age": 30}' | jq .
Outputs the input JSON in a human-readable format.
Extracting a Specific Field
echo '{"name": "Bob", "age": 25}' | jq '.name'
Extracts the value of the 'name' field from a JSON object.
Extracting Fields from Array Elements
echo '[{"name": "Alice"}, {"name": "Bob"}]' | jq '.[].name'
Extracts the 'name' field from each object within a JSON array.
Raw String Output
echo '{"city": "Seoul"}' | jq -r '.city'
Outputs the extracted string value without quotes.
Selecting Multiple Fields and Creating a New Object
echo '{"name": "Charlie", "age": 40, "email": "charlie@example.com"}' | jq '{name: .name, age: .age}'
Creates a new object containing only the 'name' and 'age' fields from an existing object.
Conditional Filtering
echo '[{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]' | jq '.[] | select(.age >= 30)'
Filters users whose age is 30 or older.
Transforming Array Elements (map)
echo '[{"name": "Alice"}, {"name": "Bob"}]' | jq 'map(.name | ascii_upcase)'
Converts each user's name to uppercase.