Answer: To get pure JSON data from the model, combine the `--output-format json` flag with `jq` to parse the response field. For example, run `gemini --output-format json "Return a raw JSON object with keys 'version' and 'deps' from @package.json" | jq -r '.response' > data.json`. Status: Confirmed Entry: tool/gemini-cli/agents-and-automation/extract-structured-json-output Revision: 1 Digest: sha256:191aee85faef2088 (changes whenever the content changes) Timeline: Created: 2026-11-13T12:39:09Z Last changed: 2026-11-13T12:39:09Z Last verified: 2026-11-20T12:51:47Z Next check: 2026-11-21T12:51:47Z Check interval: Daily Expected change: No fixed schedule Data: Field | Value | Source | As of flag | --output-format json | [1] | 2026-11-20 example command | gemini --output-format json "Return a raw JSON object with keys 'version' and 'deps' from @package.json" | jq -r '.response' > data.json | [1] | 2026-11-20 script filename | generate_json.sh | [1] | 2026-11-20 Windows script filename | generate_json.ps1 | [1] | 2026-11-20 output file | data.json | [1] | 2026-11-20 Sources: [1] Google. "Automate tasks with headless mode". https://geminicli.com/docs/cli/tutorials/automation.md Role: primary. Accessed: 2026-11-20T12:51:47Z Quote: "combine the `--output-format json` flag with `jq` to parse the response field" (Supports: flag) Quote: "gemini --output-format json "Return a raw JSON object with keys 'version' and 'deps' from @package.json" | jq -r '.response' > data.json" (Supports: example command) Quote: "Save the following script as `generate_json.sh`" (Supports: script filename) Quote: "or `generate_json.ps1` for Windows" (Supports: Windows script filename) Quote: "Check `data.json`. The file should look like this:" (Supports: output file) Published: 2026-10-16T02:36:07Z Snapshot SHA-256: b91e786382d8ff961a0eb4f79ef13444627abdcc5e58c0a92ff82dca93a10bf6 (captured 2026-11-13T03:17:54Z) Verification: Method: Automated extraction from [1] with deepseek-flash (JSON output, thinking disabled). Every value was checked by code to appear verbatim in a quoted passage of [1]. On this check the text of [1] was unchanged since 2026-11-13T12:39:09Z, so the values verified then were kept. Cross-check: not-available at 2026-11-20T12:51:47Z. No independent second source is configured for this entry Last successful check: 2026-11-20T12:51:47Z Last attempt: 2026-11-20T12:51:47Z Notes and limitations: Extracted automatically from a single official source (section "Extract structured JSON data"). Related: https://latestn.com/tool/gemini-cli/agents-and-automation/headless-json-output-format How do I get JSON output from Gemini CLI in headless mode? https://latestn.com/tool/gemini-cli/agents-and-automation/hook-exit-codes What exit codes do Gemini CLI hook scripts need to return? https://latestn.com/tool/gemini-cli/agents-and-automation/hook-input-schema What input fields does a Gemini CLI hook receive on stdin? https://latestn.com/tool/gemini-cli/agents-and-automation/create-hook-script How do I create a hook script for Gemini CLI? https://latestn.com/tool/gemini-cli/agents-and-automation/create-skill-with-prompt How do I create a new Agent Skill in Gemini CLI using a prompt? https://latestn.com/tool/gemini-cli/agents-and-automation/define-remote-subagent How do I define a remote subagent in Gemini CLI? https://latestn.com/tool/ All entries in AI tools Change log: Time | Event | Change | Source 2026-11-13T12:39:09Z | added | Entry created | — Changes for this entry as a feed: https://latestn.com/tool/gemini-cli/agents-and-automation/extract-structured-json-output/latest Challenge this entry: Open challenges: None How: If a value here is wrong or out of date, send what is wrong and a link to evidence. Challenges are queued and checked against the evidence; they do not change the entry by themselves. If the entry changes as a result, the change log says so. Form: https://latestn.com/dispute/tool/gemini-cli/agents-and-automation/extract-structured-json-output POST: https://latestn.com/dispute/tool/gemini-cli/agents-and-automation/extract-structured-json-output with claim, evidence_url, and optionally field and contact (form-encoded or JSON) GET: https://latestn.com/dispute/tool/gemini-cli/agents-and-automation/extract-structured-json-output?claim={what is wrong}&evidence_url={link} How to cite: LatestN. (2026). How do I get structured JSON output from Gemini CLI for use in scripts? Revision 1, last verified 2026-11-20T12:51:47Z. https://latestn.com/tool/gemini-cli/agents-and-automation/extract-structured-json-output (accessed 2026-11-21T10:01:51Z). @misc{LatestN_tool_gemini_cli_agents_and_automation_extract_structured_json_output_r1, title = {How do I get structured JSON output from Gemini CLI for use in scripts?}, author = {{LatestN}}, year = {2026}, howpublished = {\url{https://latestn.com/tool/gemini-cli/agents-and-automation/extract-structured-json-output}}, note = {Revision 1; digest sha256:191aee85faef2088; last verified 2026-11-20T12:51:47Z; accessed 2026-11-21T10:01:51Z} } Reuse: License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/) Attribution: Copying and adapting are allowed, including commercially, if you credit LatestN and link to the entry you used. Each entry ends with a ready-made citation. URL: https://latestn.com/tool/gemini-cli/agents-and-automation/extract-structured-json-output