AI

JSON Prompting Guide: Templates, Examples and Real Tests

JSON prompting tested on Claude: JSON prompts gave clean JSON 88% of the time vs 33% for plain text. 8 templates, image and video tips, when to skip it.

JSON Prompting Guide: Templates, Examples and Real Tests

JSON prompting means writing your AI instructions as labeled fields (task, rules, output format) instead of a paragraph, and in my October 2026 test on Claude it raised the share of clean, ready to parse JSON replies from 33% to 88%.

After nearly 20 years in AI development and digital marketing, I've seen plenty of prompt tricks go viral and fade. So I ran 474 scored API calls on Claude Opus 5.5, Sonnet 5.5 and Haiku 5.5 to see what JSON prompts change, and where they don't help at all.

My Main Points:

  • JSON prompts returned clean JSON a program can read in 53 of 60 replies; the same requests in plain text managed 20 of 60.
  • JSON prompting didn't make Claude more accurate: all 120 extraction replies got every field right in both formats.
  • JSON prompts helped Sonnet 5.5 follow every writing rule in 11 of 20 replies instead of 3 of 20, while Opus 5.5 was perfect either way.
  • Claude Opus 5.5 and Sonnet 5.5 refused all 18 prompts that asked for a "reasoning" field, but a short "explanation" field worked every time.
  • JSON prompts cost 32% to 73% more input tokens, about 100 to 140 tokens per prompt.
  • For apps that must always get valid JSON, the API's structured outputs feature beats any prompt.

In this guide, I'll show you how I tested it, eight JSON prompt templates you can copy (or build in our free JSON prompt generator), and the cases where plain text still wins.

What Is a JSON Prompt?

A JSON prompt is an AI instruction written as named fields in JSON (JavaScript Object Notation), the key and value format apps use to pass data to each other. A normal prompt reads like this:

Write a product description for a handmade leather wallet. Keep it between 120 and 160 words, mention the 10 year warranty once, include the price $89, use exactly 3 bullet points and end with a call to action that starts with "Order".

The same request as a JSON prompt looks like this:

Follow the instructions in this JSON prompt exactly. Treat every field as a requirement.

{
  "task": "Write a product description",
  "product": "Handmade leather wallet",
  "output": {
    "length": "120 to 160 words",
    "structure": "intro, 3 bullet points, call to action"
  },
  "constraints": [
    "Mention the 10-year warranty exactly once",
    "Include the price $89",
    "End with a call to action that starts with the word \"Order\""
  ]
}

A JSON prompt carries the same information as the paragraph, with every rule in its own slot, so the model doesn't have to guess which words are requirements and which are background.

JSON Prompting vs Normal Prompting: What My Claude Test Showed

JSON prompting beat normal prompting on format and rule following in my test, and tied it on accuracy. The same Claude models found the same facts either way, and the JSON versions delivered them in a cleaner, more predictable shape.

How I Tested JSON vs Plain Prompts

I sent every prompt through the Anthropic API on October 25, 2026, to Claude Opus 5.5, Claude Sonnet 5.5 and Claude Haiku 5.5. Each plain prompt carried exactly the same facts and rules as its JSON twin, and code scored every reply, so no judgment calls were involved.

  • Two extraction tasks: pull 7 invoice fields from a short email, and 11 fields from a harder one with two companies, an old quote to ignore, and VAT and a due date to work out. 10 runs per format per model.
  • Two writing tasks: a product description with 7 checkable rules and a LinkedIn post with 10 (word range, exact phrases, 3 hashtags on the last line, no emojis, banned words). 10 runs each.
  • Reasoning: 18 math and logic problems with checked answers, each asked as a plain prompt, as JSON asking for the answer only, and as JSON with an extra field for the working.

Every call used the same short system prompt, the same medium effort level and no tools. The whole test cost about $2. Templates 2, 3 and 4 below are the exact JSON prompts I used.

JSON Prompts Returned Clean JSON Far More Often

JSON prompts produced JSON a program can read directly in 53 of 60 extraction replies, against 20 of 60 for plain prompts. Opus 5.5 went from 1 of 20 to 13 of 20, Sonnet 5.5 from 10 of 20 to 20 of 20, and Haiku 5.5 from 9 of 20 to 20 of 20.

Chart: clean JSON replies, plain prompt vs JSON prompt. Opus 5.5 5% vs 65%, Sonnet 5.5 50% vs 100%, Haiku 5.5 45% vs 100%
Share of extraction replies that parsed as JSON with no cleanup, 20 replies per bar. Source: MPG ONE test on the Claude API, October 2026.

Every "failed" reply still held correct JSON, wrapped in a markdown code fence (```json) that a person skips over and a program expecting raw JSON chokes on. Field accuracy was identical: all 120 extraction replies, plain and JSON, got every field right, including the tricky VAT total and due date.

JSON Prompts Helped Sonnet Follow Every Rule

JSON prompts raised Sonnet 5.5's share of writing replies that passed every check from 3 of 20 to 11 of 20. Opus 5.5 passed all 20 in both formats, and Haiku 5.5 went from 18 of 20 to 19 of 20.

Chart: writing replies that passed every rule, plain vs JSON prompt. Opus 5.5 100% vs 100%, Sonnet 5.5 15% vs 55%, Haiku 5.5 90% vs 95%
Share of writing replies that passed all 7 or 10 checks, 20 replies per bar. Source: MPG ONE test on the Claude API, October 2026.

Sonnet's misses were almost all about length. With the plain prompt its product descriptions averaged 170 words against a 160 word limit; with a separate "length" field they averaged 154. In my results, JSON prompting helped most where a model was already a little loose with a rule and made no difference where it wasn't.

JSON Prompting Barely Changed Reasoning, but One Field Got Refused

JSON prompting didn't hurt accuracy on the 18 reasoning problems: every model solved all 18 in every format, with one exception. Sonnet 5.5, told to return only {"answer": ...}, broke the format on a letter puzzle by reasoning in plain text, writing a wrong JSON answer, then correcting itself in a second one.

Adding a reasoning field before the answer, a popular JSON prompting trick, backfired. Claude Opus 5.5 and Sonnet 5.5 refused all 18 prompts with "reasoning": "your step by step working", returning a refusal labeled reasoning_extraction. Haiku 5.5 answered all 18. When I renamed the field to "explanation": "a short explanation of how you got the answer, in 1 to 3 sentences" or "steps", there were zero refusals and every answer was right. I suspect the newer models guard their hidden thinking, and a field asking for "your step by step working" looks like a request for it.

What Published Research Says About JSON Prompting

Published research on JSON prompting points the same way as my test. A 2024 study by He and colleagues found that prompt format alone (plain text, Markdown, JSON or YAML) changed GPT-3.5's score by up to 40% on a code translation task, while the larger GPT-4 barely cared. That matches my results: format mattered for Sonnet and Haiku and not for Opus.

The "Let Me Speak Freely?" study (Tam et al., 2024) found the opposite risk: forcing models to answer in strict formats like JSON caused a significant drop in reasoning, and stricter formats hurt more. Today's thinking models mostly reason before they write, which is likely why I saw only one such failure.

Practitioners say the same about clarity. In a March 2026 video on JSON prompts for Gemini, the AI Mind Revolution channel argues that a clearly structured text prompt "will work as well as a JSON format". My data agrees on accuracy, while JSON prompts still did far better on machine readable output.

How to Write a JSON Prompt

Writing a JSON prompt takes three fields and one line of instructions. Start here and add fields only when you need them:

Follow the instructions in this JSON prompt exactly. Treat every field as a requirement.

{
  "task": "what you want, stated as an action",
  "constraints": [
    "one rule per item"
  ],
  "output": {
    "format": "markdown | JSON | plain text",
    "length": "e.g. 5 bullets or 300 words"
  }
}

Without that first line, models sometimes analyze your JSON instead of carrying it out. Every JSON prompt in my test used it.

MPG ONE's free JSON prompt generator: fill in the task, role and constraint fields and copy a clean JSON prompt for ChatGPT, Claude or Gemini
The free JSON prompt generator builds these fields from a form and always outputs valid JSON.

The JSON prompt fields worth knowing, from most to least useful in my experience:

FieldWhat it doesWhen to use it
taskThe action you wantAlways
constraintsHard rules, one per array itemWhenever a rule must be kept
outputFormat, length, structure and languageAlways
example_outputA short sample to copy the style fromWhen the style matters
contextBackground: who, what and whyWhen the task needs it
audienceWho reads the resultFor anything public
roleA persona for the modelOptional; it changes less than most guides claim

JSON Prompt Templates You Can Copy

The JSON prompt templates below cover the jobs I run most. Replace the values, keep the structure, and add the instruction line from the previous section on top. You can also assemble any of them in the generator.

1. Content Brief

{
  "task": "Write a blog article",
  "topic": "How small law firms can automate client intake",
  "audience": "Managing partners at firms with 2 to 20 lawyers",
  "output": {
    "format": "markdown with H2 sections",
    "length": "1200 to 1500 words"
  },
  "must_include": [
    "a cost comparison table",
    "3 software categories",
    "an FAQ"
  ],
  "constraints": [
    "No invented statistics",
    "Cite a source for every number",
    "US English"
  ]
}

2. Data Extraction (Used in My Test)

{
  "task": "Extract invoice details from the email",
  "output": {
    "format": "JSON only, no other text",
    "schema": {
      "company": "string",
      "invoice_number": "string",
      "amount": "number",
      "currency": "ISO 4217 code",
      "due_date": "YYYY-MM-DD",
      "purchase_order": "string or null",
      "contact_name": "string"
    }
  },
  "constraints": [
    "Use null for missing fields, never guess",
    "Return only the JSON object"
  ],
  "email": "...paste the text here..."
}

3. Writing With Hard Rules (Used in My Test)

{
  "task": "Write a product description",
  "product": {
    "name": "Handmade leather wallet",
    "facts": [
      "full-grain leather",
      "hand-stitched in Porto",
      "6 card slots",
      "10-year warranty",
      "price $89"
    ]
  },
  "output": {
    "length": "120 to 160 words",
    "structure": "short intro, exactly 3 bullet points, closing call to action"
  },
  "constraints": [
    "Mention the 10-year warranty exactly once",
    "No exclamation marks",
    "Never use the words: luxury, premium, elevate, timeless",
    "End with a one-sentence call to action that starts with the word \"Order\""
  ]
}

4. Social Post With Rules (Used in My Test)

{
  "task": "Write a LinkedIn post announcing a webinar",
  "facts": [
    "topic: how small businesses get cited by AI search",
    "date: June 18",
    "length: 40 minutes"
  ],
  "output": {
    "length": "90 to 120 words, not counting hashtags",
    "first_line": "a question",
    "last_line": "exactly 3 hashtags and nothing else"
  },
  "constraints": [
    "Use the exact phrase \"free webinar\" exactly once",
    "No emojis, bullet points or numbered lists"
  ]
}

5. Support Triage Agent

{
  "role": "Customer support triage agent",
  "task": "Classify the message and draft a reply",
  "rules": [
    "Refund requests over $200: escalate, promise nothing",
    "Bug reports: ask for browser and account email if missing"
  ],
  "output": {
    "format": "JSON",
    "schema": {
      "category": "refund | bug | question | other",
      "urgency": "1 to 5",
      "draft_reply": "string",
      "escalate": "boolean"
    }
  }
}

This pattern is the starting point for most support bots. If you are building one, our guide on how to create an AI agent covers the next steps.

6. Image Prompt

{
  "subject": "a ceramic coffee cup on a walnut desk, steam rising",
  "composition": "close-up, cup on the left third, blurred bookshelf behind",
  "lighting": "soft morning window light from the right",
  "style": "editorial product photo, natural colors",
  "camera": "50mm, f/2.8, eye level",
  "avoid": [
    "text",
    "logos",
    "extra cups"
  ]
}

7. Video Shot

{
  "shot": {
    "subject": "a barista pouring latte art, close-up on the cup",
    "camera": "slow push-in, 35mm, shallow depth of field",
    "motion": [
      "milk starts swirling",
      "a rosetta pattern forms",
      "steam rises as the camera stops"
    ],
    "lighting": "warm window light from the left",
    "duration": "8 seconds",
    "style": "cinematic, no text overlays"
  },
  "avoid": [
    "morphing hands",
    "extra fingers"
  ]
}

8. Reasoning With a Short Explanation

{
  "task": "Solve the problem",
  "problem": "...",
  "output": {
    "format": "JSON only",
    "schema": {
      "explanation": "a short explanation of how you got the answer, in 1 to 3 sentences",
      "answer": "the final answer only"
    }
  },
  "constraints": [
    "Return only the JSON object",
    "Fill in explanation before answer"
  ]
}

Template 8 is the version that got through on every Claude model in my test. Don't name the field "reasoning" or ask for "your step by step working" on Claude Opus 5.5 or Sonnet 5.5.

JSON Prompts for Image and Video Generation

JSON prompts work especially well for image and video models, because a shot splits naturally into separate settings: subject, composition, camera, lighting and motion. A short prose prompt leaves most of those choices to the model; fields make you decide them.

In a June 2026 demo by Creating with Conor, a plain prompt left the camera parked in one spot for the whole clip; the JSON version with a camera field describing two moves got exactly that movement, and a motion field split into stages played out in order. (The video promotes a paid tool through affiliate links.) The gain came from details the fields made him write. Plain text could carry them too, but a field is harder to forget.

JSON also helps you reverse engineer an image. The AI Mind Revolution video above shows a useful workflow for image models like Nano Banana Pro:

  1. Upload an image and ask: "Describe this image as JSON: subject, objects, style, lighting, composition and colors."
  2. Change one field, for example the lighting or one object.
  3. Paste the edited JSON back with "Create an image that follows this JSON exactly."

The same field approach works for video models like Google Veo 3. Start from template 7, and when one part of a clip comes out wrong, fix that field and keep the rest.

JSON Prompting vs Structured Outputs

JSON prompting asks a model for JSON; structured outputs force it. If your app breaks on bad JSON, use the API's structured outputs feature instead of relying on a prompt.

When OpenAI introduced Structured Outputs in August 2024, gpt-4o-2024-08-06 scored 100% on its complex JSON schema test, against less than 40% for gpt-4-0613 working from instructions alone. OpenAI's older JSON mode only guaranteed valid JSON, not that it matched your schema.

Claude and Gemini work the same way:

  • Claude: structured outputs turn your JSON schema into a grammar that constrains what Claude can write, so the reply always parses.
  • Gemini: Google's structured output docs warn that asking for JSON without a schema "acts only as a strong hint" and can still produce malformed JSON; with a schema, the output follows it.

I use JSON prompting in chat windows, for quick jobs and for anything a person reads, and structured outputs whenever code reads the result. Our ChatGPT API guide covers the API side.

When JSON Prompting Hurts

JSON prompting is overhead for many everyday tasks. Skip it in these cases:

  • One off questions. "What year did the Berlin Wall fall?" needs a sentence, not a schema.
  • Creative writing. Stories, slogans and brainstorming suffer when you squeeze them into fields. The "Let Me Speak Freely?" study found strict formats hurt reasoning too, and creative work needs even more room.
  • Conversations. Follow ups and edits flow better in plain text once the context is set.
  • Answer only output on hard problems. Demanding {"answer": ...} and nothing else made Sonnet 5.5 break the format once in my test. Give the model room with a short explanation field (template 8).
  • Tight token budgets. My JSON prompts were 32% to 73% longer than the same requests in plain text: 349 tokens against 251 for the simple extraction, 333 against 193 for the product description.

JSON vs TOON, YAML and XML Prompts

JSON isn't the cheapest format for sending data to a model. TOON (Token-Oriented Object Notation), a format built for LLM prompts, matched JSON's accuracy in its own benchmark (72.2% against 71.4%) while using 42.6% fewer tokens: 2,474 tokens against 4,308 for formatted JSON, 2,892 for compact JSON, 3,487 for YAML and 4,909 for XML.

Chart: tokens to send the same dataset, by format. TOON 2474, JSON compact 2892, YAML 3487, JSON formatted 4308, XML 4909
Tokens needed to send one benchmark dataset to an LLM, by format; retrieval accuracy was 69% to 72% for all of them. Source: TOON format benchmarks.

TOON suits data, especially long, uniform tables like product lists or logs, and its makers note that JSON can be more efficient for deeply nested data. For instructions, the choice is between JSON and XML tags: Anthropic's prompting best practices recommend tags like <instructions> and <context> to help Claude separate the parts of a prompt.

Write instructions in JSON or XML tags, whichever you find easier to read, send big uniform data as TOON or CSV, and stay consistent within a prompt.

Common JSON Prompting Mistakes

The JSON prompting mistakes below cost me the most, in client work and in this test:

  • Too many fields. Fifteen fields where four would do dilutes attention. Start with task, constraints and output.
  • Rules in one long string. "constraints": "be brief, no jargon, US English" gets partly ignored. Put each rule in its own array item.
  • No instruction line. Bare JSON sometimes gets analyzed instead of carried out.
  • Trusting "JSON only". Even with that rule, Opus 5.5 wrapped 7 of 20 JSON prompt replies in a code fence. Strip fences before parsing, or use structured outputs.
  • A "reasoning" field on Claude. Opus 5.5 and Sonnet 5.5 refused every prompt that asked for one. Use a short "explanation" or "steps" field instead.
  • No example. When style matters, one good sample in example_output beats any adjective in a tone field.

FAQ

What is a JSON prompt example?

A JSON prompt example is {"task": "Write a product description", "constraints": ["120 to 160 words", "Mention the warranty once"], "output": {"format": "markdown"}}. Each field holds one part of the request, so the model can tell rules from background.

What is the JSON prompt format?

The JSON prompt format is a JSON object with at least three fields: task, constraints (one rule per array item) and output. Put one line above it, such as "Follow the instructions in this JSON prompt exactly", so the model runs it instead of analyzing it.

Is JSON prompting better than normal prompting?

JSON prompting is better for format and rule following, not for accuracy. In my October 2026 test on Claude, JSON prompts returned clean, ready to parse JSON in 53 of 60 replies against 20 of 60 for plain prompts, while both formats got every field right.

Does JSON prompting work for Veo 3 and Nano Banana?

JSON prompting works well for image and video models like Veo 3 and Nano Banana Pro, because a shot splits naturally into fields such as subject, camera, lighting and motion. The gain comes from spelling out details a short prose prompt leaves to the model.

Do JSON prompts use more tokens?

JSON prompts use more input tokens. In my test the JSON versions were 32% to 73% longer than the same request in plain text, about 100 to 140 extra tokens each, which is small next to the cost of a retry.

Final Thoughts

JSON prompting earns its place when you need the same shape every time: data a program reads, writing with hard rules, image and video shots with many settings. In my test it lifted clean JSON from 33% to 88% of replies and helped the less careful model keep its rules, while accuracy stayed the same.

Skip it for quick questions, creative work and conversations, use structured outputs when an app depends on the result, and on Claude, ask for a short explanation instead of "reasoning". If you want structured prompts built into your own content or document workflows, that's exactly what our generative AI development services team does.

Mohamed Ezz portrait
About the author

Mohamed Ezz

CEO & Founder at MPG ONE

Mohamed Ezz is the CEO and Founder of MPG ONE, guiding the agency across AI development, talent management, marketing, SEO, and media strategy.