JSON Mode
An API setting that constrains an LLM to output valid JSON without enforcing a specific schema.
JSON mode is the simplest form of structured output. When enabled, the API guarantees the model's response is valid, parseable JSON. It does not constrain what keys or values are present - just that the output can be parsed with JSON.parse() without throwing.
JSON mode vs JSON Schema enforcement
JSON mode produces valid JSON with any structure. JSON Schema enforcement validates JSON against a specific schema definition. If you need specific fields (for example, {"summary": string, "sentiment": "positive" | "negative"}), JSON mode alone is insufficient - the model might output {"answer": "positive"} instead. Use full function calling or structured output APIs with schema validation for strict field requirements.
When JSON mode is sufficient
JSON mode works well when your prompt reliably produces a consistent structure and you want to guard against occasional formatting errors such as stray text before the JSON or missing closing braces. For prototyping and lightweight extraction tasks, it often provides the right tradeoff: simpler to implement than a full schema while still guaranteeing parseable output.
Enabling JSON mode
OpenAI: response_format: { type: "json_object" }. Anthropic: use their structured output feature or implement tool calls with JSON response parsing. Always include "JSON" or the expected structure in your prompt itself - models without a prompt hint can produce empty objects or non-JSON output.