JSON Mode
JSON mode is an API option, introduced by OpenAI at its DevDay in November 2023, that makes a large language model reply with valid JSON (JavaScript Object Notation) instead of free text, so that downstream code can parse the answer reliably.[1] It guarantees valid JSON syntax but not that the output follows a particular schema; schema adherence is the job of the later Structured Outputs feature.[2][3]
What does JSON Mode mean in simple terms?
Normally an LLM (large language model) answers in free-form sentences. JSON mode is a switch in the API request that makes it answer with a tidy JSON object made of keys and values instead. With it on, your code can read a value directly if that field is present, for example result["price"], rather than digging it out of a paragraph. In OpenAI's Chat Completions API you turn it on with response_format={"type": "json_object"}, and the messages must also tell the model to produce JSON.[4] What it does not do is check that the right fields are there: a reply can be valid JSON and still miss a field you need.[2] It is often the first option teams meet when they hand data extraction, classification or tool calls to an AI system.
How can JSON Mode be explained with an analogy?
It is like a company rule that quotes must be submitted on the standard spreadsheet template rather than as free-form documents. The rule guarantees a spreadsheet arrives, but not that every column is filled in correctly.
Where is JSON Mode used?
OpenAI — Launched at DevDay 2023
On November 6, 2023, OpenAI announced JSON mode alongside GPT-4 Turbo and an updated GPT-3.5 Turbo. The new response_format parameter constrains the model to produce a syntactically correct JSON object, and OpenAI positioned it for developers generating JSON in the Chat Completions API outside of function calling.[1] In the same announcement, OpenAI said its internal evaluations showed a 38% improvement for the new GPT-3.5 Turbo (gpt-3.5-turbo-1106) on format-following tasks such as generating JSON, XML and YAML.[1] OpenAI's current guide describes Structured Outputs as the evolution of JSON mode and recommends using it instead when possible.[2]
Result: 38% improvement on format-following tasks for gpt-3.5-turbo-1106 (OpenAI internal evaluation, compared with earlier models).[1]
Quote extraction — A two-step rollout (hypothetical example)
Imagine a team that pulls line items, unit prices and tax from supplier quotes into its ERP system. As a first step it turns on JSON mode, so complete, successful replies can be parsed; it still checks for refusals and truncated output. It then finds that some replies are valid JSON but are missing a required field, which JSON mode does not prevent.[2][4] As a second step it moves to Structured Outputs with a JSON Schema and strict: true, so replies match the schema.[3] Recording parse failures and missing fields at each step makes it easier to compare models or settings later. This is an illustrative scenario, not a real company's results.
Agents and tool calls — From valid JSON to matching the schema
When an agent calls tools such as a database query or a payment API, its arguments must have the right field names and types. When OpenAI introduced Structured Outputs in August 2024, it said JSON mode improves the reliability of valid JSON but does not guarantee conformance to a schema, and offered strict: true on function definitions.[3] On OpenAI's evaluation of complex JSON schema following, gpt-4o-2024-08-06 with Structured Outputs scored 100%, compared with less than 40% for gpt-4-0613.[3] Anthropic offers a similar option: strict: true on Claude tool definitions validates tool names and inputs against the schema.[6]
Result: 100% on OpenAI's complex schema-following eval with Structured Outputs (gpt-4o-2024-08-06), vs under 40% for gpt-4-0613 (OpenAI internal evaluation).[3]
Claude and Gemini — Schema-based JSON across providers
Other model providers offer schema-based JSON output. Anthropic's Claude API provides structured outputs through output_config.format with a JSON Schema and uses constrained decoding; the feature first shipped behind the beta header structured-outputs-2025-11-13, which is no longer required.[6] Google's Gemini API returns JSON when the MIME type is set to application/json together with a schema, and its SDKs accept schemas defined with Pydantic (Python) or Zod (JavaScript).[5] Parameter names differ between providers and change over time, so check each provider's current documentation before building.[2][5][6]
Result: OpenAI, Anthropic and Google all document schema-based JSON output in their current APIs (checked October 2026).[2][5][6]
Try it today
- Check your model provider's documentation for which models support JSON mode and which support schema-based structured outputs.[2][5][6]
- In an OpenAI call, set
response_format={"type": "json_object"}and add a line to the system message such as "Respond in JSON."; without the word JSON in the messages, the request is rejected.[4] - Run the same task with Structured Outputs:
response_format={"type": "json_schema", "json_schema": {"name": ..., "strict": true, "schema": ...}}, and compare whether required fields are always present.[3] - Reproduce the case with other providers: Gemini with the
application/jsonMIME type plus a schema, and Claude withoutput_config.format.[5][6] - Before parsing, check whether the reply was cut off (for example
finish_reason=length), and track parse failures and missing fields on a dashboard as a regression test when you change models or settings.[4]
Limits and direction
The main limit, stated in OpenAI's and Microsoft's documentation, is that JSON mode guarantees valid JSON but not a specific schema, even if the schema is described in the prompt.[2][4] If the messages do not ask for JSON, OpenAI warns that the model may generate an unending stream of whitespace until it reaches the token limit, which wastes time and cost.[4] A reply can also be cut off at the token limit and leave partial JSON.[4] Even with schema enforcement, values can still be wrong (for example, a mistake in a calculation), so validate values in your application.[3][5] A model may still refuse an unsafe request; OpenAI's Structured Outputs returns a separate refusal value, and Claude marks it with stop_reason: "refusal", so handle refusals and empty results separately.[3][6] On Claude, prefilling the assistant message is not compatible with JSON outputs.[6]
The direction is clear: from "valid JSON" to "matches the schema". OpenAI introduced Structured Outputs on August 6, 2024; it uses constrained decoding, which masks tokens that would break the supplied schema at each sampling step.[3] OpenAI now recommends Structured Outputs over JSON mode when possible, while JSON mode remains supported.[2] Anthropic and Google offer comparable schema-based outputs.[5][6] For new work, JSON mode is a reasonable first step, while schema-based structured outputs are the safer choice when downstream code depends on specific fields.
Schema-based outputs support a provider-specific subset of JSON Schema. Check the supported constraints, handle refusals and truncation, and validate values before taking action. Claude currently documents an additional exception for the capitalization of string enum and const values; these may differ only in capitalization, so design the schema and validation accordingly.[2][6]
Which concepts are related to JSON Mode?
- Related conceptPrompt VersionIn prompt and AI workflow practice, when a prompt changes, check that the JSON output still parses.
- Related conceptPrompt LibraryIn prompt and AI workflow practice, shared prompts can include a standard JSON output instruction.
- Related conceptPersona PromptingIn prompt and AI workflow practice, a persona shapes tone, while JSON mode shapes the output format.
Which sources explain JSON Mode?
- OpenAI — New models and developer products announced at DevDay (2023-11-06) — https://openai.com/index/new-models-and-developer-products-announced-at-devday/
- OpenAI API Docs — Structured model outputs (Structured Outputs vs JSON mode) — https://developers.openai.com/api/docs/guides/structured-outputs
- OpenAI — Introducing Structured Outputs in the API (2024-08-06) — https://openai.com/index/introducing-structured-outputs-in-the-api/
- Microsoft Learn — Learn how to use JSON mode (Azure OpenAI in Microsoft Foundry, updated 2026-05-13) — https://learn.microsoft.com/en-us/azure/foundry/openai/how-to/json-mode
- Google AI for Developers — Structured outputs (Gemini API, updated 2026-09-23) — https://ai.google.dev/gemini-api/docs/structured-output
- Anthropic — Structured outputs (Claude Platform Docs) — https://platform.claude.com/docs/en/build-with-claude/structured-outputs
Tell us what you think
Your feedback helps us improve the content.