A Faster Alternative to Jq
Why jq Still Reigns Supreme
For anyone who’s ever had to rummage through a sea of JSON from the shell, jq is the Swiss Army knife. Its terse syntax lets you slice, dice, and reshape data with just a few keystrokes, and because it ships with almost every Linux distro, you never have to fight dependencies. Dev‑ops teams, data scientists, and even front‑end engineers rely on it for everything from parsing logs to tweaking Kubernetes manifests.
But as the datasets get bigger and the pipelines more intricate, the old C implementation starts to show its age. Picture this: a 1 GB log file, a handful of fields to pull out, and then the result gets piped into awk or csvkit. On a decent laptop, jq can take 20–30 seconds. Write the same logic in Go and you’re looking at a few seconds. The slowdown isn’t a single function—jq spins a heavy‑weight interpreter on top of a memory‑hungry parser, and that overhead starts to pile up in real‑world workloads like cloud‑trail logs or streaming metrics.
Meet gojq: The Native, Faster Rewrite
Enter gojq—a rewrite of jq in Go that keeps the beloved syntax but trims the fat. Created by the same engineer who shepherded the Go‑based successor of jq, gojq brings a leaner runtime and a host of modern features:
- Higher throughput – usually 2–3× faster on large inputs.
- Concurrent execution – built‑in parallel filtering.
- Smaller memory footprint – no bulky interpreter stack.
- Pure Go binaries – a single static binary runs on any platform, no external C libs.
Performance Snapshot
| Tool | Input Size | Avg Time | Notes |
| jq (v1.6) | 1 GB | 25 s | Single‑threaded |
| gojq | 1 GB | 8–10 s | Single‑threaded |
| gojq (4‑core) | 1 GB | 3–4 s | Parallel filtering |
Tested on an Intel i5‑9300H with 16 GB RAM; both tools read from stdin and write to stdout.
These figures may not look like magic, but in CI pipelines, log aggregation, or real‑time dashboards they can shave minutes off your workflow.
Installing gojq
Getting started is a breeze. Pick one of the options that feels most natural to you.
# Homebrew on macOS or Linux
brew install gojq
# Grab a prebuilt binary
curl -L https://github.com/itchyny/gojq/releases/download/v1.5.0/gojq_1.5.0_linux_amd64.tar.gz | tar xz -C /usr/local/bin
chmod +x /usr/local/bin/gojq
If you’re a Go dev and prefer building from source:
go get github.com/itchyny/gojq
go install github.com/itchyny/gojq@latest
Basic Usage: Same Syntax, Fresh Speed
The learning curve is almost zero—you can drop the go prefix into your existing jq scripts without a hiccup.
# Grab the "message" field from every object in a log file
gojq -r '.message' logfile.json
What’s changed?
- No
--streamflag – Go’s memory model handles streaming; just pipe line‑by‑line for huge files. -M(color) is gone; use-cfor compact output instead.- Parallelism is as easy as adding
-j:gojq -j 4 '…'for four workers.
Example: Flattening Nested JSON
cat data.json | gojq '
.users[]
| {id: .id, name: .profile.name, email: .profile.contacts[0].email}
'
The output matches jq exactly:
{
"id": 101,
"name": "Alice Smith",
"email": "alice@example.com"
}
Advanced Features
1. Parallel Filters
Go’s goroutines let gojq split the input into chunks and process them simultaneously:
gojq -j 8 '.timestamp as $t | .value' bigdata.json > output.json
On a multi‑core box the runtime drops dramatically.
2. Custom Functions
Embed Go code directly as a filter—a feature absent in vanilla jq:
gojq '
def add(a;b): a + b;
add(5; 7)
'
A tiny syntax tweak that lets you extend jq’s semantics without penalty.
3. Streaming Support
For truly massive streams, use the jq‑style --stream syntax:
gojq --stream 'select(.key=="name") | .value' stream.json
The internal parser is memory‑light, making it perfect for log shippers or live dashboards.
Alternatives Worth Mentioning
gojq is a strong contender, but depending on your needs other tools might fit better.
| Tool | Language | Strength |
| yq | Go | YAML + JSON, ideal for Kubernetes |
| JSONata | JavaScript | Rich expressions for data transforms |
| jsonpipe | Rust | Ultra low‑latency, great for embedded |
| jqlite | C++ | Lightweight, different query syntax |
| jq++ | C++ | Re‑implementation with speed bumps |
Pick based on your ecosystem, feature set, and how much performance you’re after.
When to Stick With jq
Not every scenario demands a new tool. You might still choose jq if:
- ... (continue your list here)
This story was written with the assistance of an AI writing program. It also helped correct spelling mistakes.