Prompt
structured JSON output api
Latest observation
Oct 9, 2026
OpenAI APIWeb search: off
If you want an API to return structured JSON output, there are a few common ways to do it:
1. Define a JSON schema
Tell the model exactly what shape you want.
Example:
{
"name": "Alice",
"age": 30,
"tags": ["developer", "python"]
}
2. Use a response format in the API
If you're using an LLM API, request JSON-only output explicitly.
Example prompt
Return only valid JSON. No markdown. No extra text.
Example output
{
"summary": "User asked about structured JSON output API",
"intent": "information_request",
"confidence": 0.92
}
3. Validate the response
Always validate the JSON on your side:
- parse it
- check required fields
- reject malformed output
- retry if needed
4. Use function/tool calling if available
Many APIs support tool/function calling, which is more reliable than free-form JSON.
Example structure:
{
"tool": "create_user",
"arguments": {
"name": "Alice",
"email": "alice@example.com"
}
}
5. Example with OpenAI-style structured output
If your API supports structured outputs, you typically provide a schema like:
{
"type": "object",
"properties": {
"title": { "type": "string" },
"priority": { "type": "string", "enum": ["low", "medium", "high"] }
},
"required": ["title", "priority"],
"additionalProperties": false
}
Then the API returns data matching that schema.
If you want, I can give you:
- a Python example
- a JavaScript example
- an OpenAI structured output example
- a JSON Schema template
Brands