JSON Mode & Schema in Ollama
From the Ollama cheat sheet ยท Structured Output ยท verified Jul 2026
JSON Mode & Schema
Use the format parameter to get structured JSON responses.
bash
# JSON mode โ free-form JSON output
curl http://localhost:11434/api/chat -d '{
"model": "llama3.2",
"messages": [{"role": "user", "content": "Tell me about Canada"}],
"format": "json",
"stream": false
}'๐ก "format": "json" ensures the model always returns valid JSON
โก Pass a JSON Schema object as "format" to enforce an exact output structure
๐ Include format instructions in your prompt too โ the model responds better with both
๐ข Schema-based output works best with larger models (7B+) for complex structures
jsonstructuredschema