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
Back to the full Ollama cheat sheet