jq
Skill1 starsChanged 3 months agoMITView on GitHub
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.
- Installs packages
In this repository22 other files it gives its agents.
- alloy-structural-analysisSkill
- analyzing-architectureSkill
- color-accessibilitySkill
- daily-briefingSkill
- design-docSkill
- diagramSkill
- eng-career-goals-writerSkill
- gh-repo-managementSkill
- git-commit-helperSkill
- jiraSkill
- morphirSkill
- newrelic-cliSkill
- oli-storage-managerSkill
- project-instructorSkill
- qmd-searchSkill
- rigorous-reviewSkill
- save-zkSkill
- scalaSkill
- smart-initSkill
- sourcegraph-searchSkill
- structured-memorySkill
- visualizeSkill
The file
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 4 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 23
Prefer this over writing a throwaway Python/Node script for the same JSON job
- Distinctive: line 25
Do not use when:
- Very specific: line 38
If missing: tell the user to install (brew install jq / apt install jq) and STOP.
- Very specific: line 61
Aggregate: if needed: group_by(.k) | map({k: .[0].k, n: length}) or map(.items | map(.price*.qty) | add)
- Very specific: line 68
NEVER redirect jq onto the same path it reads: jq ...
- Very specific: line 80
Run via shell: jq [flags] '<filter>' <file> or pipe into jq.
- Distinctive: line 84
Always include the exact command in the user-facing answer.
- Very specific: line 113
Avoid -s on large/NDJSON inputs for simple work.
- Distinctive: line 114
No shell-injecting user text into the filter body.
- Very specific: line 115
Prefer jq over Python/Node for the same JSON transform.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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.jsonDeep 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.jsonGuardrails
- 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 | sortUpdate config safely
jq '.version="2.0.0" | .scripts.build="tsc -b"' package.json > package.json.tmp && mv package.json.tmp package.jsonEnv-safe lookup
jq --arg name "$TARGET_NAME" '.users[] | select(.name == $name)' users.jsonNon-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
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

