JSON Toolkit

jq Alternatives Compared: gojq, jaq, yq, Miller and Plain Python, Tested

Bottom line: jq is not the only answer on the command line. jaq is faster on big files but memory-hungry, gojq can be embedded as a Go library but starts slow, yq belongs to YAML, Miller owns tabular work, and for simple filters plain Python can actually win. Benchmarks plus hands-on tests turn this into a per-scenario decision table, with four traps to know before you switch.

Advanced~5 min readPublished 2026-11-23Updated 2026-11-23
Comparison of jq and its alternatives gojq, jaq, yq and Miller on the command line

jq's filter language is nearly irreplaceable, but "jq is already installed" is not the same as "jq is the optimal tool for this job" — the cost of picking the wrong tool is not a few extra seconds, it is an 8 GB machine failing outright on a 1 GB file.

Command-line JSON processing is daily routine for every backend and data engineer, and jq is the default answer for almost everyone. The problem with a default answer is that it gets used in every scenario, including the ones it is bad at: multi-megabyte files, YAML-hybrid pipelines, tabular statistics, and tasks too simple to justify a query language at all. This article puts jq and its four most-cited alternatives — gojq, jaq, yq, and Miller — into one table, adds plain Python as the "no special tool at all" baseline, and answers one question: when should you switch, and when should you absolutely not.

Third-party numbers below are cited with their sources and sample sizes. Everything marked as a local re-test ran on Linux with jq 1.7, Python 3.11.1, and yq v4.44.6, against a sample of 200,000 NDJSON log lines (23.6 MB), using /usr/bin/time -v for wall-clock time and peak resident memory.

1. First, tell apart the three kinds of "alternative"

Before comparing tools, be clear about which part of jq you want to replace. jq is really three things bundled together: a parser (reads JSON text into memory), a filter language (transform, select, reduce syntax), and a CLI shell (pipe-friendly, zero configuration). Tools marketed as "jq replacements" replace different layers:

  • gojq and jaq replace the parser and interpreter implementation while keeping jq's filter syntax — your scripts barely change; what changes is engine speed, memory behavior, and edge-case compatibility;
  • yq replaces the format circle: it extends jq-style syntax to YAML, XML, and TOML, with JSON as a format it also happens to support;
  • Miller (mlr) throws away the filter language entirely: it builds pipelines from verbs (filter, cut, stats1) and treats CSV/TSV tabular data as a first-class citizen;
  • Plain Python / Node scripts replace the whole bundle: once task logic goes beyond "filter and pick a few fields", the readability of a general-purpose language starts to beat the terseness of a query language.

Once this layer distinction is clear, the benchmark data below means something: you are never really comparing "who is fastest" but "which layer's overhead dominates this task".

2. The three jq implementations: jq, gojq, jaq

Same filter, three engines; differences concentrate in speed, memory, and semantic details. Two reliable data sources: the benchmark suite maintained in the jaq repository, where in the 2025 round jaq 3.0 won 20 of 31 benchmarks, jq 1.8.1 won 5, and gojq 0.12.18 won 6; and sanand0's extended benchmark (large-sample multi-task averages), where jaq finished first overall at 0.321s — about 1.6x faster than jq at 0.502s — with gojq close to jq. DevLearn's 200k-log-line test adds the memory dimension: streaming a 76 MB filter workload, jq 1.7 took 1.17s / 3.7 MB, jaq 3.1 took 1.27s / 81.8 MB — jaq slightly faster, but with 22x the resident memory.

Tool Language Speed Memory When to pick it
jq 1.7/1.8 C Baseline Lowest (3.7 MB class when streaming) Scripts, CI, Dockerfiles — it is the one everyone has
jaq 3.x Rust 30–40% faster on big files; wins 20/31 in the suite High (81.8 MB class on the same task) Loop-processing multi-MB files; native YAML/TOML/CBOR/XML input
gojq 0.12 Go Close to jq, slowest startup Medium (9.8 MB class) Embedding as a Go library; dependency-free cross-platform binary

The selection rule in one sentence: jq buys you "it's everywhere", jaq buys you speed, gojq buys you "you can import it". Note that jaq has no resource limits — a malicious or simply buggy filter can OOM the process, which you must treat as a security concern in long-running services. Also, jaq is not 100% semantically identical to jq; run your real filter set against it before you swap it into CI.

3. Outside the JSON circle: where yq and Miller shine

yq (the mikefarah version) has the widest format matrix, converting between YAML, JSON, XML, TOML, and CSV while preserving comments and formatting — for YAML config files it is genuinely irreplaceable. But handing it heavy JSON work is a mistake: in sanand0's benchmark yq averages 10.7x slower than the fastest tool. I re-tested the same "filter plus field extraction" task locally (200k NDJSON lines, 23.6 MB): jq took 0.36s, yq with -p=json whole-document parsing took 6.82s — roughly 19x slower. yq's correct positioning is YAML first, JSON incidentally; for batch YAML processing it is a weapon — DevLearn measured a 9.2 MB YAML read-modify-write at 1.4–1.5s with gojq versus over 40 seconds for pure-Python PyYAML.

Miller's killer feature is tabular data. mlr --ijson --ocsv stats1 -a mean,median -f ms logs.ndjson produces latency statistics in one line, without hand-writing a reduce like you would in jq; its verb model is naturally friendly to CSV input and output, and it should be your first pick when the team needs maintainable CSV scripts. The costs: it does not stream very large single documents, and its syntax is a whole new language — count the team learning curve. There is also a SQL route for tabular queries: dsq and sq run SELECT directly against JSON files using DuckDB or SQLite; when you think in "rows and columns" rather than "trees", SQL feels far more natural than a filter language.

4. The counter-intuitive one: plain Python wins simple tasks

The most striking number in DevLearn's benchmark: filtering 200k log lines and extracting three fields, a 20-line Python script did it in 0.97s / 11.4 MB — faster than jq at 1.17s / 3.7 MB. The reason is easy to see: jq runs its filter semantics on its own VM for every input value, while the Python side is a compiled script driving a C-implemented standard-library parser, with logic so simple it reduces to one integer comparison. When interpreter overhead exceeds the expressiveness a query language buys you, Python wins that round fairly.

I re-tested this claim locally: filtering status >= 500 and emitting {id, ms} from 200k NDJSON lines (23.6 MB), jq 1.7 took 0.31s / 3.7 MB while line-by-line json.loads on Python 3.11 took 0.45s / 11 MB — this time jq was about 30% faster with a third of the memory. Two experiments with opposite conclusions precisely locate the boundary: the simpler the task and the larger the sample, the more the jq-vs-Python gap converges toward interpreter overhead; once logic gets complex (joins, grouping, p95, nested conditionals), Python's development-speed advantage dominates. The test is simple: if the logic needs functions, use Python; if it is still a one-line "filter + transform + count", use jq.

# Baseline script: read NDJSON line by line, filter + pick fields (0.45s / 11 MB)
import json, sys
w = sys.stdout.write
with open("logs.ndjson", encoding="utf-8") as f:
    for line in f:
        r = json.loads(line)
        if r["status"] >= 500:
            w(json.dumps({"id": r["id"], "ms": r["ms"]}) + "\n")
# The same task in jq (0.31s / 3.7 MB)
jq -c 'select(.status >= 500) | {id, ms}' logs.ndjson

5. A per-scenario decision table

The data above condenses into this cheat sheet. Every row's "why" traces back to the measurements and citations in sections 2 through 4:

Scenario First choice Alternative Why
One-liner JSON lookup in the terminal jq jaq It's everywhere; on small files the speed gap is negligible
CI batch-processing multi-MB JSON jq / jaq gojq jaq is 30–40% faster, but confirm the memory budget
Logic complex enough to need functions Python/Node — A general language's readability beats a filter language
Streaming big arrays to save memory jq --stream ijson / stream-json jq on line-per-record input is already O(1) memory
Batch YAML read-modify-write yq / gojq — gojq reads YAML roughly 28x faster than PyYAML
Tabular stats and CSV output Miller dsq / sq Verbs + SQL both beat a hand-written reduce
Embedding queries inside a Go service gojq — The only importable jq-syntax implementation
Finding where a value lives in JSON gron / jsongrep jq grep-compatible output; no query language needed

This table assumes "single machine, batch processing, file-based". If your scenario is real-time validation inside a long-running service, the per-query subprocess-spawn cost of a CLI shell becomes the bottleneck — switch to in-language libraries (Jackson, jsonpath-ng and friends) instead. Command-line tools and process boundaries are two different problems.

6. Four traps to know before switching

Trap 1: jq has no -i. None of the jq-family tools (including most alternatives) offer an in-place edit flag; jq '.x = 1' f.json > f.json applies the redirection truncation before jq reads the file, wiping it — something every jq user steps on once. Write to a temp file and mv, or use sponge.

# Wrong: f.json gets truncated to an empty file
jq '.version = 2' config.json > config.json
# Right: write a temp file first
jq '.version = 2' config.json > config.json.tmp && mv config.json.tmp config.json

Trap 2: -s is a memory amplifier. slurp reads the entire input into one array before handing it to the filter. On the same statistics task, my local test measured peak memory of 3.7 MB with streaming reduce inputs versus 185 MB with -s — a 22.6 MB sample amplified about 8x, and DevLearn's 76 MB sample amplified 197x. Filtering, per-record transforms, and per-record counting never need the "whole picture"; when in doubt, write the streaming version first. The extended discipline lives in our jq streaming benchmarks for large files.

Trap 3: interpolating shell variables into filters. jq ".name == \"$VAR\"" explodes when the variable contains quotes, newlines, or $ — and it is an injection risk. Pass parameters with --arg name "$VAR" (strings) or --argjson (JSON values) and reference $name inside the filter. The whole jq family follows this convention; switching implementations does not excuse the bad habit.

Trap 4: treating jaq/gojq as drop-in jq. Both have documented semantic differences from jq (gojq's number handling, jaq's missing built-ins), and jaq adds no resource limits. Before switching, run your repository's real filter set against both — benchmarks measure someone else's task, your filters are your task.

7. When you should absolutely not switch

Three red lines. First, if the team docs, script library, CI, and Dockerfiles all assume jq, swapping implementations for a 5ms-vs-3ms difference is self-sabotage. Second, the moment a filter exceeds three lines and grows named variables and reduce, rewriting it in Python beats debugging a jq program — env.dev's rule of thumb is that break-even arrives around your first named variable. Third, when the output feeds the next Unix tool, jq's output discipline (-r, --raw-output0) is the most mature; alternatives may not match it.

Conversely, these signals mean it is time to act: log files growing into hundreds of MB while CI starts timing out (try jaq or go streaming); batch YAML rewrites taking tens of seconds (yq/gojq, bypassing PyYAML); statistics scripts with reduce nested three levels deep (Miller or SQL); and spending ten minutes recalling syntax every time you touch a filter (Python — honestly admit this is not a query-language job).

FAQ

Which is actually faster, jaq or gojq?

jaq, on big files: its own benchmark suite wins 20 of 31 cases, and sanand0's extended benchmark averages 0.321s overall — fastest in the field. But peak memory runs 20x higher than jq, and there are no resource limits. Memory-sensitive environments (small containers, shared CI runners) should stay on jq or gojq; throughput-sensitive batch processing should take jaq.

My server only has Python, no jq — is installing jq worth it?

Yes, but split by task. For everyday filtering one jq line replaces twenty Python lines, and on streaming NDJSON jq uses less memory (3.7 MB vs 11 MB in my test). For complex business logic or an existing Python stack, do not force a swap for "toolchain uniformity" — keep both and choose per the section 5 table.

Can yq fully replace jq for JSON?

No. yq's JSON engine goes through its YAML parsing path; on pure JSON tasks it measured an order of magnitude slower than jq (19x locally; 10.7x on average in sanand0's benchmark). yq's home turf is YAML/multi-format conversion with comment preservation; heavy JSON belongs to jq or jaq.

Miller's syntax differs a lot from jq — is the learning curve worth it?

Depends on your output. If your consumers are tabular anyway (reports, Excel, database imports), Miller's verb model does in one line what a hand-written jq reduce does in ten, and the learning cost pays back in days. If your output stays a JSON tree, staying in the jq ecosystem is less friction.

Which tool should stream-process large files?

For NDJSON, one object per line, jq's default per-input processing is already O(1) memory with no flags; only a single large-array document needs jq --stream, Python's ijson, or Node's stream-json. Full measurements of memory multiples and streaming patterns are in our jq streaming benchmarks for large files and how to open large JSON files.