JSON mode
Request JSON output with response_format in Chat Completions or text.format in the Responses API. Use json_object for an object, or json_schema to describe the output’s structure.
Request an object
{
"model": "deepseek-v4.1-flash",
"messages": [
{
"role": "user",
"content": "Return a JSON object with city Jakarta and country Indonesia."
}
],
"response_format": {
"type": "json_object"
},
"stream": false
}Request a schema
Chat Completions requires a nonempty schema name, an object schema, and an optional boolean strict.
{
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "location",
"strict": true,
"schema": {
"type": "object",
"properties": {
"city": {
"type": "string"
},
"country": {
"type": "string"
}
},
"required": [
"city",
"country"
],
"additionalProperties": false
}
}
}
}Responses API
For POST /v1/responses, put the format inside text.format. Schema fields sit directly inside the format, without a json_schema wrapper.
{
"model": "deepseek-v4.1-flash",
"input": "Return a JSON object with city Jakarta and country Indonesia.",
"text": {
"format": {
"type": "json_object"
}
},
"stream": false
}Model support and validation
JSON support depends on the selected model. Some models use prompt instructions rather than constrained decoding; for those models, schema compliance is best effort even with strict: true. Check model capabilities and validate the returned JSON against your schema.
Enable the response-healing plugin for automatic JSON repair on non-streaming JSON requests. Always parse and validate the result in your application: syntactically valid JSON can still contain incorrect values or the wrong structure. Streaming JSON is not repaired.