jq Command Generator Prompt
Generate a precise jq command from sample JSON and a stated transformation, with shell-safe quoting, null handling, explanations, and test cases.
Prompt Template
You are a senior command-line engineer generating a jq filter only from the JSON structure, desired output, jq version, and shell context I supply. Do not invent keys or claim the filter works until it has been tested against representative valid and edge-case inputs. Representative input JSON: [paste a small sanitized sample] Input shape authority: [canonical schema, representative sample, partial example, unknown] Desired output with exact example: [paste] Transformation steps: [select, map, group, sort, join, reshape, aggregate, update] Input mode: [single JSON value, JSON Lines, stream, multiple files] jq version: [version or unknown] Shell and operating system: [bash, zsh, fish, PowerShell, cmd, other] Invocation context: [interactive command, script, CI, Makefile, npm script, container] Raw versus JSON output: [requirements] Null, missing-key, empty-array, wrong-type, and malformed-input behavior: [requirements] Ordering and duplicate rules: [details] Numbers, dates, Unicode, and large-value constraints: [details] External variables and arguments: [names and sample values] Performance or memory constraints: [file size, streaming requirement, unknown] Safety boundary: [read-only transformation, file replacement workflow, secrets present, untrusted input] Provide: 1. A short interpretation of the requested transformation and any unresolved schema questions. 2. The smallest readable jq filter, followed by the complete shell command with quoting appropriate to the verified shell. 3. A step-by-step explanation of each filter stage and operator. 4. Explicit handling for missing, null, empty, and wrong-type values according to the supplied requirements. 5. A readable expanded version when the compact filter is difficult to maintain. 6. Test fixtures for normal, empty, missing, null, wrong-type, and boundary inputs, with expected outputs. 7. A safe validation command that leaves the source file unchanged. 8. If file replacement is requested, a temporary-file and successful-parse workflow with backup guidance; never redirect onto the input file. 9. Version or portability notes for jq and the selected shell. 10. A final audit for invented keys, unsafe interpolation, quoting errors, unintended raw output, slurp or streaming mistakes, precision loss, and untested assumptions. Do not expose secrets, interpolate untrusted shell text, overwrite the input directly, invent successful execution, or recommend eval. Use --arg, --argjson, or equivalent safe argument passing where appropriate. If the sample does not establish the structure, ask for a schema or use guarded type checks.
Example Output
Assumptions
- Input is one object with an items array.
- Missing status is excluded.
- amount must be numeric; invalid entries are ignored.
Filter
.items | map(select(.status == $status and (.amount | type == "number"))) | map({id, amount}) | sort_by(.amount)
Shell Command
jq --arg status 'open' '.items | map(select(.status == $status and (.amount | type == "number"))) | map({id, amount}) | sort_by(.amount)' input.json
Edge Checks
- Empty items returns [].
- A missing items key needs an agreed policy before finalizing; use (.items? // []) only if treating missing as empty is correct.
- Source data remains unchanged because the command writes to standard output.
Validation
Run the filter against normal, empty, null, and wrong-type fixtures and compare each result with the stated expected JSON.
Tips for Best Results
- ๐กProvide a canonical schema or several representative samples because one JSON object cannot prove every shape.
- ๐กState the shell explicitly; quoting that works in zsh or bash may not work in PowerShell or cmd.
- ๐กTest missing, null, empty, and wrong-type values before using a generated filter in automation.
Frequently Asked Questions
What is the jq Command Generator Prompt prompt?
Generate a precise jq command from sample JSON and a stated transformation, with shell-safe quoting, null handling, explanations, and test cases. It's a free ChatGPT prompt template from our Coding collection โ copy it, fill in the bracketed variables, and paste it into your AI tool.
Which AI tools work with this prompt?
It's written and tested for ChatGPT, Claude and Gemini. Any AI assistant that accepts free-form text prompts will handle it well.
How do I customize this ChatGPT prompt?
Replace the bracketed variables โ such as [paste a small sanitized sample], [paste], [version or unknown] โ with your own details before running it. Provide a canonical schema or several representative samples because one JSON object cannot prove every shape.
Is this prompt free to use?
Yes. Every prompt on PromptAtlas is free to copy, customize, and use โ no signup required.
Related Prompts
Code Review Assistant
Get a thorough, senior-level code review with actionable feedback on quality, security, performance, and best practices.
Debugging Detective
Systematically debug errors and unexpected behavior with root cause analysis and fix suggestions.
Code Refactoring Advisor
Transform messy, complex code into clean, maintainable, well-structured code with clear explanations.