Skip to main content
JSON mode forces a model to emit syntactically valid JSON. It’s a feature of the OpenAI Chat Completions API, enabled by setting response_format to {"type": "json_object"}. Use JSON mode when you need parseable JSON but don’t need to enforce a specific schema. For most production use cases, prefer structured outputs. Structured outputs constrain successful, complete responses to a JSON schema you provide. Handle refusals, output limits, and transport errors before accepting the parsed result; schema constraints don’t guarantee that every request completes.
On Model APIs, Muse Spark Open accepts json_object but doesn’t constrain output to JSON. Ask for JSON in your prompt and validate the response in your application.

How it works

Set BASETEN_API_KEY to your Baseten API key and install the OpenAI SDK with pip install openai. JSON mode tells the server to constrain the output to valid JSON. You still describe the fields you want in the prompt; the server only enforces well-formedness, not shape. To generate a JSON object: Run the following script:
Ask for JSON in the prompt so the model produces a useful shape. The server constrains output to valid JSON but doesn’t infer the schema from the request.

JSON mode versus structured outputs

Reach for JSON mode when you don’t want to define a schema and the downstream consumer can tolerate flexible field sets. Otherwise, use structured outputs.

Model support

JSON mode and structured outputs are supported on a per-model basis. See the feature support table on the Model APIs overview for which models support each.