jq Command Line Tool for Working with JSON

Опубликовано: 16 Март 2026
на канале: LinuxHowTo
32
1

In this video, we’ll show you how to use the jq command-line tool for working with JSON data. jq is a lightweight and powerful tool for slicing, dicing, and pretty-printing JSON data. We’ll cover basic usage, extracting values, filtering arrays, and a real-world example of parsing JSON data from an API. Whether you’re dealing with JSON files, configurations, or API responses, jq is your go-to tool. Let’s dive into the details and master jq!

Learn:
✅ What is jq?
jq is a lightweight command-line tool for slicing, dicing, and pretty-printing JSON data.

1. Basic Usage
Pretty Print JSON:

echo '{"name":"adam","age":30}' | jq '.'
This pretty-prints the JSON data.

Format JSON File:

cat data.json | jq
This formats the JSON file for better readability.

2. Extract Values
Get Specific Field:

echo '{"user":"alice","score":95}' | jq '.user'
This extracts the value of the user field.

Extract from File:

jq '.message' data.json
This extracts the value of the message field from a JSON file.

3. Filter Arrays
Extract All IDs:

echo '[{"id":1},{"id":2}]' | jq '.[].id'
This extracts all id values from an array of objects.

Filter Objects:

jq '.[] | select(.age 〉 25)' users.json
This filters objects where the age field is greater than 25.

4. Real-World Example
Current Real-Time Location of the International Space Station (ISS):

curl http://api.open-notify.org/iss-now.json | jq '.iss_position.latitude, .iss_position.longitude'
This fetches the current location of the ISS and extracts the latitude and longitude.

✅ Pro Tips:
Install jq: Ensure jq is installed on your system. You can install it using:
sudo apt install jq
Explore Documentation: jq has extensive documentation and community support. Explore these resources to get the most out of jq.
Combine with Other Tools: Use jq in combination with other command-line tools like curl, grep, and awk for powerful data processing pipelines.

GitLab Link: You can find more information and example scripts for this video at this GitLab link: https://gitlab.com/hatem-badawi/linux....

Hit subscribe for more Linux tips and like if this helped.
Let us know: What’s your favorite use case for jq?

👉 Watch now and master using jq for working with JSON data!

#LinuxTips #jqTool #JSON #CommandLine #ProductivityHacks

(Short, clear, and packed with practical knowledge!)