Jq
Skill tkolleh/skills/jq
My personal directory of AI Agent skills
npx -y skills add tkolleh/skills --skill jqAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Trigger on: jq, jq filter, jq query, process JSON, filter JSON, transform JSON, extract from JSON, parse API response JSON, NDJSON, pretty-print JSON, jq select, group_by JSON, update JSON file with jq. Specialized procedure for complex JSON processing with the jq CLI. Prefer over ad-hoc Python/Node one-offs for extract, filter, format, aggregate, or in-place JSON transforms. Do not use for binary files, CSV/XML conversion, or general scripting unrelated to JSON.
The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
5.5 KB, as published. Nobody here has run it
jq — JSON processing with the jq CLI
When to use
- User wants to extract, filter, transform, aggregate, or pretty-print JSON with
jq - Input is JSON / JSON array / NDJSON (newline-delimited JSON), API payloads, logs, configs
- Prefer this over writing a throwaway Python/Node script for the same JSON job
Do not use when:
- File is binary, CSV, XML, YAML-only (unless already converted to JSON)
- Task is general bash/Python scripting with no JSON core
- User only needs to open/edit JSON in an editor (no filter)
Prerequisites
command -v jq >/dev/null || { echo "jq not installed"; exit 1; }
jq --version # expect 1.6+
If missing: tell the user to install (brew install jq / apt install jq) and STOP.
Procedure
Work phases in order. Do not skip. Prefer pure jq over python/node for JSON work.
Phase 1 — Structure analysis
- Identify inputs: path(s), stdin, or API response the user provided.
- Peek schema before complex filters:
- Small file:
jq 'type, (if type=="array" then length else keys end)' <file> - Huge / unknown:
jq -c 'limit(1; .)' <file>or first NDJSON line viahead -n 1 - Validate:
jq empty <file>— non-zero exit → report parse error and STOP
- Small file:
- Note shape: object vs array vs NDJSON stream; nested keys needed; size class (<10MB / large).
- Completion: input path(s) known, type known, filter target keys identified (or error reported).
Phase 2 — Filter construction
Design filter with explicit pipeline stages (compose with |):
- Select path into focus:
.items[],.[],.data.results? - Filter rows:
select(.status == "active") - Transform shape:
{id, name: .user.name}ormap(...) - Aggregate if needed:
group_by(.k) | map({k: .[0].k, n: length})ormap(.items | map(.price*.qty) | add) - Output flags: pretty default;
-rbare strings;-ccompact;-sonly if slurp is required
Safety (mandatory):
- Pass untrusted strings via
--arg/--argjson, never interpolate into the filter string - Optional paths: use
?(.a.b?) to avoid hard errors on missing keys - NEVER redirect jq onto the same path it reads:
jq ... file > filetruncates the file. Always:
jq '<filter>' file.json > file.json.tmp && mv file.json.tmp file.json
Deep cookbook (load only if needed): references/patterns.md
- Completion: one copy-pastable
jq ...command ready;--argused where user/env text is involved.
Phase 3 — Execution
- Run via shell:
jq [flags] '<filter>' <file>or pipe intojq. - File rewrites: temp +
mvonly (see Safety). - Large files / NDJSON: stream; do not
jq -sfor simple filters/counts. - On non-zero exit: capture stderr; fix or report; do not invent output.
- Always include the exact command in the user-facing answer.
- Completion: command ran; stdout/stderr captured; exit code known.
Phase 4 — Validation
- Empty result → re-check with
keys, sample object,?/ casing. - Confirm output type matches request (JSON vs raw list vs count).
- For file writes:
jq empty file.jsonand spot-check changed + preserved fields. - Return command + short summary + truncated sample if large.
- Completion: answer matches intent, or clear failure + diagnostic.
Essential patterns (keep loaded)
jq '.users[] | select(.age > 21)' data.json
jq 'map({name: .user.name, role: .auth.role})' data.json
jq 'group_by(.category) | map({cat: .[0].category, count: length})' data.json
jq --arg id "$ID" '.[] | select(.id == $id)' data.json
jq -r '.[].title' pulls.json
jq -c 'select(.level=="error" and .service=="auth")' app.ndjson | wc -l
jq '.version="2.0.0"' package.json > package.json.tmp && mv package.json.tmp package.json
# nested totals example
jq '[.orders[] | select(.status=="paid") | {buyer: .buyer.name, total: ([.items[] | .price*.qty] | add)}] | sort_by(-.total)' orders.json
Guardrails
- Validate JSON first (
jq empty). --arg/--argjsonfor external values; single-quote filters in the shell.- Avoid
-son large/NDJSON inputs for simple work. - No shell-injecting user text into the filter body.
- Prefer
jqover Python/Node for the same JSON transform. - File rewrite: temp +
mvonly; neverjq ... f > f.
Examples
Extract names (raw)
jq -r '.users[] | select(.status=="active" and .age>21) | .name' users.json | sort
Update config safely
jq '.version="2.0.0" | .scripts.build="tsc -b"' package.json > package.json.tmp && mv package.json.tmp package.json
Env-safe lookup
jq --arg name "$TARGET_NAME" '.users[] | select(.name == $name)' users.json
Non-trigger
"Convert this CSV" / "write a Python ETL" → do not load this skill.
References (load only if needed)
references/patterns.md— streaming, merge, walk, try/catch, group_by detail