Prompt
JSON output AI API
Latest observation
Oct 8, 2026
OpenAI APIWeb search: off
If you want an AI API to return JSON output, the common approach is:
- Ask for JSON in the prompt
- Use a response format / schema option if the API supports it
- Validate the returned JSON in your code
Example prompt
Return your answer as valid JSON with these keys:
- title (string)
- summary (string)
- tags (array of strings)
Example expected output
{
"title": "Example",
"summary": "A short summary.",
"tags": ["ai", "api", "json"]
}
If you’re using an AI API with structured output support
Many modern APIs let you specify a JSON schema or “structured output” mode, for example:
response_format: jsonresponse_format: json_schema- function/tool calling
- strict structured responses
Best practices
- Make the schema explicit
- Tell the model to return only JSON
- Avoid markdown fences unless you really need them
- Validate and retry if parsing fails
Example Python check
import json
response_text = '{"title":"Example","summary":"A short summary.","tags":["ai","api","json"]}'
data = json.loads(response_text)
print(data["title"])
If you want, I can show you how to do this with a specific API like:
- OpenAI
- Anthropic
- Gemini
- Azure OpenAI
- a custom REST API