Skip to content

JSON to Prompt Generator

Turn a JSON sample into a structured prompt template — typed field list, worked example and a JSON Schema, all derived from one document.

Sample of the JSON you want back

7 fields

Prompt template

1,588 characters
<task>
Extract the requested fields from the input below.
</task>

<fields>
- issue (string): The issue.
- product (string): The product.
- urgency (string): The urgency.
- tags (array of string): The tags. A list.
- reporter (object): The reporter.
- reporter.name (string): The name.
- reporter.plan (string): The plan.
</fields>

<schema>
```json
{
  "type": "object",
  "properties": {
    "issue": {
      "type": "string"
    },
    "product": {
      "type": "string"
    },
    "urgency": {
      "type": "string"
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "reporter": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "plan": {
          "type": "string"
        }
      },
      "required": [
        "name",
        "plan"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "issue",
    "product",
    "urgency",
    "tags",
    "reporter"
  ],
  "additionalProperties": false
}
```
</schema>

<example>
```json
{
  "issue": "Cannot reset password — the email never arrives",
  "product": "Acme Cloud",
  "urgency": "high",
  "tags": [
    "auth",
    "email"
  ],
  "reporter": {
    "name": "Dana Lin",
    "plan": "pro"
  }
}
```
</example>

<input>
{{input}}
</input>

<output_contract>
Return a single JSON object and nothing else.
Do not wrap the JSON in a code fence.
Do not add commentary before or after the JSON.
Every field listed above must be present. Use null where a value is genuinely unknown.
</output_contract>

Template options

Structure

Fields

7
PathTypeDescription
issuestringThe issue.
productstringThe product.
urgencystringThe urgency.
tagsarray of stringThe tags. A list.
reporterobjectThe reporter.
reporter.namestringThe name.
reporter.planstringThe plan.

Generated in your browser — the sample is never uploaded. The schema block is already inside the structured-outputs strict subset; check or extend it with the Structured Output Schema Builder.

About the JSON to Prompt Generator

This JSON to prompt generator turns a sample of the object you want a model to return into the prompt that asks for it: a typed field list, a worked example, a JSON Schema, and an output contract. All four are derived from the same document, so they cannot contradict each other — which is the actual problem it solves.

Writing this prompt by hand means stating the same field list three times: once as prose, once as an example, once as a schema. They agree on the day you write them and drift the moment a field is added. Deriving all three from one sample makes that drift impossible rather than merely unlikely.

Nothing is invented. Field descriptions come from the key name and the observed type — publishedAt becomes "The published at", which is clumsy and honest. A generator that guessed at semantics would put text into a shipped prompt that nothing in your sample supports, and you would not notice until the model acted on it.

Anything the sample cannot answer is marked in the output rather than filled in. An empty array has no knowable element type, so it is left as an explicit TODO; a field missing from some records is marked optional so you can confirm that is what you meant.

The schema block is emitted inside OpenAI's structured-outputs strict subset — every object closed, every property required — so it can be pasted into response_format without further editing.

  • One sample in; field list, example, JSON Schema and output contract out, all consistent by construction
  • XML-tag structure (the Anthropic convention) or Markdown headings
  • Strict-mode JSON Schema, ready for response_format without edits
  • Type inference that merges across array elements, so unions and optional fields are detected honestly
  • Gaps surfaced explicitly — empty arrays and sometimes-absent fields are reported, never guessed
  • An {{input}} placeholder, so the result is a template rather than a one-off
  • Every section individually removable, to trade tokens against reliability

How to use it

  1. Paste an example of the JSON you want the model to return. One representative object is enough.
  2. Paste an array of two or three objects instead if some fields are optional — the generator detects which are missing from part of the sample and marks them.
  3. Write the task line. This is the only part not derived from your sample, and it is the instruction everything else supports.
  4. Choose XML tags or Markdown headings. XML parses unambiguously; Markdown is the more common house style.
  5. Read the gaps panel. Anything listed there is something the sample could not tell the generator.
  6. Copy the template and replace {{input}} with the document you want processed.

Real-world use cases

Backend & API developers

Turn the exact JSON shape an endpoint needs to return into the prompt that asks an LLM step to produce it, starting from a real sample response rather than writing the field list from memory.

AI & LLM application engineers

Keep a prompt's field list, worked example and JSON Schema from drifting apart as the target shape changes during development — regenerate all three from one updated sample instead of editing them separately.

Data & ETL engineers

Convert a webhook payload or warehouse row into a reusable {{input}} template for a batch LLM pipeline, with optional fields flagged automatically from an array sample.

QA & eval engineers

Build the output contract for a prompt-testing fixture — the JSON Schema and the four parse-failure rules it emits are the pass/fail criteria every model response gets checked against.

Solutions & integration engineers

Adapt a partner's API response into a documented structured-prompt template while wiring an LLM step into a third-party integration, without inventing field descriptions the partner's docs never gave.

Examples

A field list derived from a sample

Input
{"title": "Dune", "year": 1965, "tags": ["sci-fi"]}
Output
- title (string): The title.
- year (number): The year.
- tags (array of string): The tags. A list.

Types come from the values, not from a declaration. An array's element type is read from what is inside it.

Optional fields, detected from an array sample

Input
[{"a": 1, "b": 2}, {"a": 3}]
Output
- a (number): The a.
- b (number, optional): The b.

b was absent from one of the two records, so it is marked optional and listed in the gaps panel for you to confirm.

An empty array is not guessed at

Input
{"items": []}
Output
- items (array — TODO: element type): The items. A list.

An empty array says nothing about what it holds. Filling in "string" would produce a prompt that asks for the wrong shape.

The output contract block

Input
Output contract enabled
Output
Return a single JSON object and nothing else.
Do not wrap the JSON in a code fence.
Do not add commentary before or after the JSON.
Every field listed above must be present. Use null where a value is genuinely unknown.

These four lines address the four most common ways a model's reply fails to parse. The AI Output Formatter exists for when it happens anyway.

Common errors

MessageCauseFix
The generated descriptions read awkwardlyThey are derived mechanically from your key names — createdAt becomes "The created at".Edit them in the copied template. The alternative was inventing a description, which would have put unverifiable text into a prompt you ship.
The model still returns extra fieldsThe prompt asks for a shape; only a strict schema enforces one.Use the generated schema block with response_format json_schema and strict: true. Prompt instructions are a request; the schema is a guarantee.
A field came out as the wrong typeThe sample had one value and the real data has others — a field that is a number in your sample but sometimes null gets typed as number.Paste an array covering the variation. The inference merges across every element, so it produces an honest union rather than whatever the first record looked like.
The template is longer than the prompt it replacesThe schema and example blocks cost tokens. They buy reliability, and are not free.Turn off whichever you do not need. The schema is the one to keep if you are using structured outputs; the example is the one to keep if you are not.

Frequently asked questions

Does the JSON I paste get uploaded anywhere?

No. It is parsed and analysed entirely in your browser, and no request is made. That matters here because the natural thing to paste is a real API response, which frequently contains customer data.

Should I use the XML or the Markdown structure?

XML tags if the input you will drop in might itself contain Markdown headings — a ## inside a user's document cannot be confused with a section boundary, whereas a heading can. It is also Anthropic's documented convention. Markdown is otherwise fine and slightly shorter.

Why does it not write better field descriptions?

Because it would have to guess. A field called status could mean an order state, an HTTP code or a boolean flag, and nothing in the sample says which. A clumsy description you will edit is better than a confident one you will not notice is wrong.

Is the generated JSON Schema valid for OpenAI structured outputs?

Yes — it is emitted inside the strict subset, with additionalProperties: false on every object and every property in required. Optional fields become nullable rather than being dropped from required, which is how strict mode expresses optionality. The schema builder on this site will confirm it.

What does the {{input}} placeholder do?

Nothing automatic — it marks where the document you want processed should go, so the output is a reusable template rather than a single prompt. Replace it in your own code, or paste over it by hand.

Can I use this with Claude or Gemini rather than OpenAI?

The prompt itself is provider-neutral, and the XML-tag style is Anthropic's own convention. Only the schema block is OpenAI-specific in its strictness rules; both other providers accept ordinary JSON Schema, which this is a subset of.

How does it decide a field is optional?

By counting. If you paste an array, a key present in some objects and absent from others is marked optional, and it is listed in the gaps panel so you confirm rather than discover it later. A single object gives no evidence either way, so nothing is marked optional.

Does it handle nested objects and arrays of objects, not just flat fields?

Yes. The field list uses dotted and bracketed paths generated by walking the sample recursively — a nested object's fields appear as reporter.name, and an array of objects appears as items[].sku. Each nested field gets its own row, type and description, the same way the top-level fields do.

Last updated