JSON
Prompting.
14 production-ready templates for structured data every time. Schema enforcement, function calling, and zero-hallucination extraction for real integrations.
The Schema-First Methodology
The most common mistake in JSON prompting is describing what you want instead of showing it. Schema-First inverts this: you define the exact output shape as a JSON skeleton, then instruct the model to populate it. The model has a rigid contract to follow rather than making structural decisions itself.
Three rules make Schema-First work: (1) Define every field with its type and constraints before the task instruction. (2) Explicitly forbid everything you don't want — markdown, explanations, code fences. (3) Specify fallback values for optional fields so the model never invents placeholders.
Define the Schema First
Provide the complete JSON structure before the task. Every field, type, and constraint declared upfront.
Forbid Everything Else
Explicitly ban markdown, code fences, and explanations. The model defaults to helpful — override it.
Specify Fallback Values
For nullable fields, define the fallback. 'string | null' prevents invented values like N/A or unknown.
How to Use These Templates
Each prompt below is a complete, production-ready template. Replace the bracketed placeholders with your actual data. Click the copy icon to grab any prompt instantly.
Quick Setup for API Use
When using the OpenAI API, add this to your system message for all JSON requests:
Also set: response_format: { type: "json_object" } for guaranteed valid JSON syntax.
Schema-Enforced Object Extraction
Extract the following data and return ONLY valid JSON. No explanation, no markdown, no code fences. Strict schema required: { "name": string, "email": string | null, "company": string | null, "role": string | null, "intent": "purchase" | "inquiry" | "support" | "other" } Input text: [PASTE_TEXT_HERE]
Array of Objects from Unstructured Data
Parse the following text and return a JSON array of objects. Each object must match this schema exactly. Return ONLY the JSON array, nothing else. Schema per item: { "id": number (auto-increment starting at 1), "title": string, "price": number (extract numeric value only), "currency": string (ISO 4217), "available": boolean } Text to parse: [PASTE_TEXT_HERE]
Nested JSON with Validation Rules
Return ONLY a JSON object matching this exact structure. All fields required. No nulls unless noted. { "order": { "id": string (UUID format), "status": "pending" | "processing" | "shipped" | "delivered" | "cancelled", "customer": { "name": string, "email": string (valid email format), "address": { "street": string, "city": string, "country": string (ISO 3166-1 alpha-2) } }, "items": [ { "sku": string, "qty": number (integer, min: 1), "unit_price": number (2 decimal places) } ], "total": number (sum of qty * unit_price), "created_at": string (ISO 8601) } } Order data: [PASTE_ORDER_DETAILS]
Sentiment Analysis with Confidence Score
Analyze the sentiment of each review and return ONLY a JSON array. No other output. Schema: [ { "review_id": number, "sentiment": "positive" | "neutral" | "negative", "confidence": number (0.00 to 1.00), "key_phrases": string[] (max 3), "action_required": boolean } ] Reviews: [PASTE_REVIEWS_HERE]
Function Call Schema Generator
Generate an OpenAI function calling schema for the following capability. Return ONLY the JSON schema object. Capability description: [DESCRIBE_FUNCTION] Output format: { "name": string (snake_case), "description": string (1-2 sentences), "parameters": { "type": "object", "properties": { [parameter_name]: { "type": string, "description": string, "enum": [...] (only if applicable) } }, "required": [...] } }
Error-Tolerant JSON with Fallback Values
Parse the input and return a JSON object. If a field cannot be determined, use the specified fallback. Never omit a field. Return ONLY valid JSON. Schema with fallbacks: { "name": string | "Unknown", "age": number | -1, "email": string | null, "tags": string[] | [], "is_verified": boolean | false, "score": number (0-100) | 0 } Input: [PASTE_INPUT]
Classification + Routing JSON
Classify the following customer message and return ONLY this JSON object: { "category": "billing" | "technical" | "sales" | "general" | "complaint" | "cancellation", "urgency": "low" | "medium" | "high" | "critical", "department": "support" | "sales" | "finance" | "engineering" | "management", "auto_resolvable": boolean, "suggested_response_type": "template" | "human" | "escalate", "keywords": string[] (up to 5 key terms extracted) } Customer message: "[PASTE_MESSAGE]"
Data Transformation: CSV Row to JSON
Convert the following CSV data into a JSON array. Each row becomes an object. Return ONLY valid JSON. Infer appropriate types (numbers, booleans, nulls) from cell values. Headers and rows: [PASTE_CSV_DATA] Rules: - Empty cells → null - "true"/"false" (case-insensitive) → boolean - Numeric strings → number - All other values → string - Column names: camelCase the header names
Multi-Step Reasoning in JSON Chain
Solve the following problem step by step and return ONLY a JSON object showing your reasoning chain. { "problem_statement": string (restate the problem in one sentence), "steps": [ { "step_number": number, "action": string (what you're doing), "reasoning": string (why), "intermediate_result": string } ], "final_answer": string, "confidence": "high" | "medium" | "low", "caveats": string[] (any important assumptions or limitations) } Problem: [DESCRIBE_PROBLEM]
JSON Diff and Merge Request
Compare these two JSON objects and return ONLY a JSON diff report: { "added": { [key]: value } (keys in B not in A), "removed": { [key]: value } (keys in A not in B), "changed": { [key]: { "old": value, "new": value } }, "unchanged_count": number } Object A: [PASTE_JSON_A] Object B: [PASTE_JSON_B]
Product Catalog Normalizer
Normalize the following product descriptions into a structured JSON catalog. Return ONLY the JSON array. [ { "sku": string (generate a unique SKU if not present, format: PROD-XXXXX), "name": string (clean, title-case product name), "category": string (infer from description), "price_usd": number | null, "features": string[] (bullet points extracted from description, max 6), "tags": string[] (SEO-friendly tags, max 8), "in_stock": boolean (assume true if not specified) } ] Raw product descriptions: [PASTE_DESCRIPTIONS]
API Response Schema Validator
You are a JSON schema validator. Given the expected schema and an actual API response, return ONLY this validation report: { "valid": boolean, "error_count": number, "errors": [ { "field": string (dot notation path), "expected_type": string, "actual_type": string, "message": string } ], "warnings": [ { "field": string, "message": string } ], "missing_required_fields": string[], "extra_fields": string[] } Expected schema: [PASTE_SCHEMA] Actual response: [PASTE_API_RESPONSE]
Meeting Notes to Action Items JSON
Extract structured action items from these meeting notes and return ONLY a JSON object: { "meeting_date": string (ISO 8601, infer or use null), "attendees": string[], "summary": string (2-3 sentences max), "action_items": [ { "id": number, "owner": string, "task": string, "due_date": string | null (ISO 8601 or relative like "EOW"), "priority": "high" | "medium" | "low", "dependencies": number[] (IDs of action items this depends on) } ], "decisions_made": string[], "open_questions": string[] } Meeting notes: [PASTE_NOTES]
Zero-Shot JSON Classification
You are a zero-shot classifier. Classify the input into one of the provided categories and return ONLY this JSON: { "input_preview": string (first 50 chars of input), "predicted_class": string (must be from the provided list), "confidence_scores": { [class_name]: number (0.00 to 1.00, all scores must sum to ~1.0) }, "top_signals": string[] (up to 3 phrases that drove the prediction) } Categories: [COMMA_SEPARATED_CLASS_LIST] Input to classify: [PASTE_INPUT]
Debugging JSON Hallucinations
When the model returns wrong or malformed JSON, use this systematic debugging workflow:
Check token limits first
Truncated output is the most common cause of invalid JSON. Increase max_tokens and verify the output isn't cut mid-object.
Validate with a JSON parser
Pipe output through JSON.parse() or Python's json.loads() before using it. Catch errors programmatically, not visually.
Feed the error back to the model
Append: 'Your previous output caused this error: [ERROR]. Return the corrected JSON only.' Models self-correct well with explicit error feedback.
Add a schema repeat at the end
Repeat the schema after your data input: 'Remember, your output must match this schema exactly: [SCHEMA]'. Reduces schema drift on long inputs.
Use temperature 0 for extraction tasks
For deterministic structured extraction, set temperature: 0. This minimizes creative deviations from your specified schema.
Frequently Asked Questions
Everything developers need to know about structured JSON output from language models.