Answer: Use the `--output-format` flag to specify the output format; for JSON output it returns a single JSON object containing the response and usage statistics. Status: Confirmed Entry: tool/gemini-cli/agents-and-automation/headless-json-output-format Revision: 1 Digest: sha256:195800392ee9bf8c (changes whenever the content changes) Timeline: Created: 2026-11-13T03:17:33Z Last changed: 2026-11-13T03:17:33Z Last verified: 2026-11-20T12:51:03Z Next check: 2026-11-21T12:51:03Z Check interval: Daily Expected change: No fixed schedule Data: Field | Value | Source | As of flag | --output-format | [1] | 2026-11-20 JSON output | Returns a single JSON object containing the response and usage statistics. | [1] | 2026-11-20 response field | response | [1] | 2026-11-20 stats field | stats | [1] | 2026-11-20 error field | error | [1] | 2026-11-20 Streaming JSON output | Returns a stream of newline-delimited JSON (JSONL) events. | [1] | 2026-11-20 Sources: [1] Google. "Headless mode reference". https://geminicli.com/docs/cli/headless.md Role: primary. Accessed: 2026-11-20T12:51:03Z Quote: "You can specify the output format using the `--output-format` flag." (Supports: flag) Quote: "Returns a single JSON object containing the response and usage statistics." (Supports: JSON output) Quote: "`response`: (string) The model's final answer." (Supports: response field) Quote: "`stats`: (object) Token usage and API latency metrics." (Supports: stats field) Quote: "`error`: (object, optional) Error details if the request failed." (Supports: error field) Quote: "Returns a stream of newline-delimited JSON (JSONL) events." (Supports: Streaming JSON output) Published: 2026-10-16T02:36:07Z Snapshot SHA-256: 0c76556026820577ca1ead8c836c590a079e637100bff9790c0f1599d0f9f172 (captured 2026-11-13T03:17:33Z) 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-13T03:17:33Z, so the values verified then were kept. Cross-check: not-available at 2026-11-20T12:51:03Z. No independent second source is configured for this entry Last successful check: 2026-11-20T12:51:03Z Last attempt: 2026-11-20T12:51:03Z Notes and limitations: Extracted automatically from a single official source (section "Output formats"). Related: 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/link-skill-local-development How do I link a Gemini CLI Agent Skill for local development? 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/gemini-cli/agents-and-automation/extract-structured-json-output How do I get structured JSON output from Gemini CLI for use in scripts? https://latestn.com/tool/ All entries in AI tools Change log: Time | Event | Change | Source 2026-11-13T03:17:33Z | added | Entry created | — Changes for this entry as a feed: https://latestn.com/tool/gemini-cli/agents-and-automation/headless-json-output-format/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/headless-json-output-format POST: https://latestn.com/dispute/tool/gemini-cli/agents-and-automation/headless-json-output-format with claim, evidence_url, and optionally field and contact (form-encoded or JSON) GET: https://latestn.com/dispute/tool/gemini-cli/agents-and-automation/headless-json-output-format?claim={what is wrong}&evidence_url={link} How to cite: LatestN. (2026). How do I get JSON output from Gemini CLI in headless mode? Revision 1, last verified 2026-11-20T12:51:03Z. https://latestn.com/tool/gemini-cli/agents-and-automation/headless-json-output-format (accessed 2026-11-21T10:02:17Z). @misc{LatestN_tool_gemini_cli_agents_and_automation_headless_json_output_format_r1, title = {How do I get JSON output from Gemini CLI in headless mode?}, author = {{LatestN}}, year = {2026}, howpublished = {\url{https://latestn.com/tool/gemini-cli/agents-and-automation/headless-json-output-format}}, note = {Revision 1; digest sha256:195800392ee9bf8c; last verified 2026-11-20T12:51:03Z; accessed 2026-11-21T10:02:17Z} } 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/headless-json-output-format