AI Model Wiki

    Skip to main content
    Back to Glossary

    JSON Mode

    JSON Mode is a feature offered by many large language model APIs that constrains the model's output to syntactically valid JSON, ensuring every response can be parsed by a machine without error handling for malformed text. When enabled, the model formats its answer as a proper JSON object or array, honouring a developer-specified schema if one is provided. This eliminates the common problem of models embedding JSON inside prose or occasionally producing broken bracket pairs.

    Think of it like asking someone to fill in a structured form instead of writing a free-hand letter. The recipient gets the same information, but it arrives in labelled fields they can process automatically rather than hunting through paragraphs of natural language.

    A typical use case is extracting structured data from a document. With JSON Mode enabled, a prompt like "Extract the author, title, and publication year from this text" reliably returns {"author": "Jane Smith", "title": "Deep Networks", "year": 2023} rather than a sentence such as "The author is Jane Smith…". In the OpenAI API this is activated by setting response_format: { type: "json_object" } in the request body; Anthropic's Claude achieves the same effect through tool definitions that enforce a typed output schema.

    JSON Mode is closely tied to Prompt Engineering, which guides what fields the JSON should contain, and to Inference, since schema enforcement adds a small amount of constraint during decoding. It complements RAG pipelines where retrieved context must be returned in a machine-readable envelope, and intersects with LLM capabilities more broadly as newer models support typed schemas (sometimes called Structured Outputs) that go beyond basic JSON validity.

    You will encounter JSON Mode whenever you are building an application that needs to pass AI output directly into a database, API, or UI component without a fragile text-parsing layer in between.

    AI Terminology
    Glossary