You've Been Reading JSON the Hard Way
Posted on Mon 29 June 2026 in Developer Tools
Have You Ever Stared at an API Response and Thought, "There Has to Be a Better Way"?
You call an API. It sends back a wall of JSON — deeply nested, hundreds of lines long, completely unreadable at a glance. You squint at it. You copy it into a formatter online. You grep for the field you need. You curse under your breath.
This happens to everyone, and it happens every day. JSON is how apps talk to each other, how APIs return data, how configs are stored. It's everywhere. But raw JSON is often a mess.
That's exactly the problem jq was built to solve.
So, What Is jq?
jq is a small command-line tool that lets you read, filter, and transform JSON — right from your terminal.
Think of it like a pair of tweezers for data. Instead of wading through an entire blob of JSON, you reach in and pull out exactly what you need.
It's free, open-source, and available on Linux and macOS. One quick install and you're ready:
brew install jq # macOS
apt install jq # Ubuntu/Debian
No configuration. No project setup. Just jq and you're good.
Your First 5 Minutes with jq
Let's say an API returns this:
{
"user": {
"name": "Priya",
"age": 28,
"email": "priya@example.com"
}
}
To grab just the name:
echo '{"user":{"name":"Priya","age":28}}' | jq '.user.name'
Output:
"Priya"
That .user.name is a jq filter — a tiny expression that tells jq where to look. The dot (.) means "go into this key." Chain them together to dig deeper. That's really all there is to the basic idea.
The Magic of Pretty-Printing
Before anything else, the most universally useful thing jq does is format ugly JSON into something readable.
curl https://api.example.com/data | jq .
That single . tells jq: give me everything, but make it pretty. Colors, indentation, structure — instantly readable. No online formatter needed.
This alone is worth the install.
Working with Arrays
Real-world JSON almost always has arrays — lists of users, products, search results. Here's how jq handles them.
Say you have:
[
{"name": "Alice", "score": 90},
{"name": "Bob", "score": 72},
{"name": "Carol", "score": 85}
]
Get all items:
jq '.[]' data.json
Get just the names:
jq '.[].name' data.json
Filter by a condition:
jq '.[] | select(.score > 80)' data.json
The | is a pipe — it passes the output of one step into the next, exactly like in bash. Chain as many steps as you need.
Reshaping Data
Here's where jq gets genuinely powerful. You can take JSON in one shape and output it in a completely different one.
jq '.[] | {student: .name, passed: (.score >= 75)}' data.json
Output:
{"student": "Alice", "passed": true}
{"student": "Bob", "passed": false}
{"student": "Carol", "passed": true}
You built a new structure from scratch — choosing what to keep, what to rename, and what to compute. No Python script, no spreadsheet, no scripting language required.
This is especially useful when you need to feed data from one tool into another and the shapes don't match.
A Quick Reference
| What you want | jq filter |
|---|---|
| Pretty-print JSON | jq . |
| Get a field | jq '.fieldname' |
| Get a nested field | jq '.a.b.c' |
| Get all array items | jq '.[]' |
| Filter by value | jq '.[] \| select(.field == "value")' |
| Count items | jq 'length' |
| Get first item | jq '.[0]' |
| Get specific keys only | jq '{name, email}' |
When Should You Reach for jq?
jq shines whenever you're:
- Debugging API responses and need to find one field fast
- Writing shell scripts that process JSON output from other tools
- Exploring data from a file or endpoint without opening a code editor
- Transforming JSON from one format to another for a downstream tool
If you work with APIs, AWS CLI, GitHub CLI, kubectl, or any kind of data pipeline — jq will save you time every single day. All of those tools output JSON. jq turns that into something you can actually work with.
The Part Most People Skip
One thing that trips beginners up: jq filters are case-sensitive and whitespace matters in the JSON structure, not in the filter. .user.name and .User.name are different things.
Also, if a field doesn't exist, jq returns null — it doesn't error out. That's usually fine, but if you're piping jq output into another command, watch for unexpected null values passing through silently.
For keys with special characters or spaces, wrap them in quotes:
jq '."first-name"' data.json
And if you want raw string output instead of JSON-encoded strings (no surrounding quotes), add the -r flag:
jq -r '.user.name' data.json
# outputs: Priya
# instead of: "Priya"
That -r flag matters when you're using jq output in a bash variable or passing it to another command.
The Takeaway
JSON doesn't have to be intimidating. With jq, you get a fast, simple way to slice through any JSON structure — no code, no setup, just one small tool and a filter expression.
Start with jq . to pretty-print. Then try .fieldname to grab a value. Before long, you'll be filtering arrays and reshaping data like a pro.
The best tools are the ones you barely notice — they just quietly make your work easier. jq is one of those tools.