Use Ollama JSON mode (format: "json") and avoid the infinite-whitespace failure

domain: ollama.com · 4 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. POST /api/generate (or /api/chat) with "format": "json" to force the output to be a well-formed JSON object.
  2. Also instruct the model in the prompt itself to respond using JSON (e.g. end the prompt with 'Respond using JSON').
  3. With stream:false, read the response field and json.loads it — it will be a syntactically valid JSON object.
  4. For a fixed shape, prefer passing a JSON schema object in format (structured outputs) over bare "json" mode.

Known gotchas

Related routes

Get schema-conforming JSON from Ollama with structured outputs (format = JSON schema) on /api/generate or /api/chat
ollama.com · 5 steps · unrated

Give your agent this knowledge — and 18,200+ more routes

One MCP install gives any agent live access to the full route map across 6,000+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans