---
title: "JSON schema generator for LLM structured output | BroadRouter"
description: "Paste sample JSON and get a strict JSON Schema for LLM structured output, with a strict-mode checker, Pydantic and Zod exports and a ready API request."
url: https://broadrouter.com/tools/json-schema-generator/
lang: en
updated: 2026-11-15
publisher: BroadRouter (a BroadNet site); API by BroadNet Inference, https://inference.broadnet.ai
---

# JSON schema generator for LLM structured output

Updated 2026-11-15

**In short:** To make an LLM return JSON in a fixed shape, send a JSON Schema as response\_format with strict: true. Strict mode needs an object root, additionalProperties: false on every object and every key listed in required, with optional fields typed as a union with null. Paste sample JSON and this tool writes that schema, plus Pydantic, Zod and a request.

Free, no sign-up, runs in your browser: nothing you type is sent anywhere.

Sample JSON{ "invoice\_number": "INV-2041", "issue\_date": "2026-10-03", "currency": "SAR", "vendor": { "name": "Al Noor Trading", "vat\_number": "300012345600003", "email": null }, "line\_items": \[ { "description": "Printer paper A4", "quantity": 10, "unit\_price": 18.5, "category": "office" }, { "description": "Toner cartridge", "quantity": 2, "unit\_price": 240, "category": "office" }, { "description": "Delivery", "quantity": 1, "unit\_price": 25, "category": "shipping", "note": "Riyadh" } \], "paid": false, "total": 690 }

Options Top-level array is several examples Use only the first item of each array Detect string formats (date, date-time, email, uuid) Repeated strings become enums Type every number as number, not integerSchema nameModel for the requestDeepSeek V4.1 Flash (broadnet/deepseek-v4.1-flash)GLM 5.3 (broadnet/glm-5.3)Qwen3.8 27B (broadnet/qwen3.8-27b)BroadNet Gemma 4 VL 26B (broadnet/gemma-4-26b-a4b)

## Strict-mode check

### Check a schema you already have

Your JSON Schema

[Get started](https://inference.broadnet.ai/account/?utm_source=broadrouter&utm_medium=referral&utm_campaign=tools-json-schema-generator&utm_content=tool) ·

The strict-mode rules come from [OpenAI's structured outputs guide](https://developers.openai.com/api/docs/guides/structured-outputs) (checked 2026-11-14). Other OpenAI-compatible servers implement structured output with their own decoders and may accept more or fewer keywords, so send one test request before you ship. The schema is inferred from one sample; check types such as integer vs number and which fields can be null.

[Report a wrong price or number](mailto:info@broadnet.ai?subject=Wrong%20price%20or%20number%20on%20JSON%20schema%20generator%20for%20LLM%20structured%20output&body=Page%3A%20https%3A%2F%2Fbroadrouter.com%2Ftools%2Fjson-schema-generator%2F%0A%0AWhat%20looks%20wrong%20(model%2C%20figure%20shown%2C%20correct%20figure%20and%20a%20source%20link%20if%20you%20have%20one)%3A%0A) (email to info@broadnet.ai, with this page's link and your inputs filled in).

## How it works

1.  Paste a sample of the JSON you want the model to return. If you paste an array of examples, tick "Top-level array is several examples" to merge them.
2.  Choose options: merge array items or use the first one, detect string formats, and turn repeated string values into enums.
3.  Read the strict-mode check under the output. It flags keywords that strict structured-output modes reject and rules the schema breaks.
4.  Copy the result as a raw JSON Schema, a ready `response_format` request, Pydantic v2 classes or a Zod schema.

## How the schema is inferred

| Sample value | Schema |
| --- | --- |
| `"text"` | `{"type": "string"}`, or with a `format` if detection is on |
| `42` / `4.2` | `integer` / `number`; mixed values become `number` |
| `true` | `boolean` |
| `null` | `["string", "null"]`, because a value that is always null tells nothing about its type |
| Object | `object`, every key in `required`, `additionalProperties: false` |
| Array | `array`; `items` merged from every element (or the first) |
| Key missing from some array items | Still required, but its type also allows `null` |
| Mixed types, e.g. 1 and "1" | `["integer", "string"]`, or `anyOf` for objects and arrays |

## Keywords the strict-mode checker flags

Based on the "Supported schemas" section of [OpenAI's structured outputs guide](https://developers.openai.com/api/docs/guides/structured-outputs), checked 2026-11-14:

-   **Error, not supported:** `allOf`, `not`, `dependentRequired`, `dependentSchemas`, `if`, `then`, `else`.
-   **Error, structure:** root not an object or root `anyOf`; an object without `additionalProperties: false`; a property missing from `required`; more than 10 levels of nesting, 5,000 properties or 1,000 enum values.
-   **Warning, not in the supported list:** `minLength`, `maxLength`, `patternProperties`, `propertyNames`, `minProperties`, `maxProperties`, `uniqueItems`, `contains`, `prefixItems`, `unevaluatedProperties`, `default` and `format` values other than date-time, time, date, duration, email, hostname, ipv4, ipv6 and uuid.
-   **Note:** `pattern`, `format`, `minimum`, `maximum`, `multipleOf`, `minItems` and `maxItems` are supported, except on fine-tuned models.

## Worked example

For the sample invoice above, `line_items` has three objects and only one has a `note`. The generator keeps `note` in `required` (strict mode needs that) but types it `["string", "null"]`, so the model writes `null` when there is no note. `unit_price` is 18.5 in one item and 240 in another, so it becomes `number`. Tick "Repeated strings become enums" and `category` becomes `enum: ["office", "shipping"]`; only do that if the list really is closed.

## Use it in a request

```
POST https://inference.broadnet.ai/v1/chat/completions
{
  "model": "broadnet/glm-5.3",
  "messages": [...],
  "response_format": {
    "type": "json_schema",
    "json_schema": { "name": "invoice", "strict": true, "schema": { ... } }
  }
}
```

The reply's `choices[0].message.content` is a JSON string that matches the schema. Parse it, then validate with the Pydantic or Zod model. Set `max_tokens` high enough for reasoning models, or the JSON can be cut off; see [why answers come back empty](https://broadrouter.com/guides/reasoning-tokens-empty-response/).

## Questions

### How do I generate a JSON schema from JSON?

Paste an example of the JSON you want and the generator infers a type for every value: objects become objects with all their keys, arrays take the type of their items, and numbers become integer or number. In strict mode every key is required and extra keys are forbidden.

### What does strict mode require in a JSON schema?

OpenAI's structured outputs docs list the rules: the root must be an object (not anyOf), every object needs `additionalProperties: false`, and every property must be in `required`. Optional fields are written as a union with null, e.g. `"type": ["string", "null"]`. Limits: up to 5,000 properties, 10 levels of nesting and 1,000 enum values.

### Which JSON Schema keywords are not supported in strict mode?

OpenAI lists `allOf`, `not`, `dependentRequired`, `dependentSchemas`, `if`, `then` and `else` as not supported, and fine-tuned models also reject `minLength`, `maxLength`, `pattern`, `format`, `minimum`, `maximum`, `multipleOf`, `patternProperties`, `minItems` and `maxItems`. Other OpenAI-compatible servers may support more or less, so test your schema.

### How do I make a field optional in structured output?

In strict mode you cannot leave a key out of `required`. Instead, keep it required and allow null: `"type": ["string", "null"]`. The model then always returns the key and writes null when it has no value. The generator does this automatically for keys that are missing from some array items.

### How do I use the schema with an OpenAI-compatible API?

Send it as `response_format` with `type: "json_schema"`, a name, `strict: true` and the schema. The "Request" tab writes the full body for https://inference.broadnet.ai/v1/chat/completions. On BroadNet Inference, GLM 5.3 and Qwen3.8 27B are listed with structured output. See [structured output](https://broadrouter.com/glossary/structured-output/).

### Can I get Pydantic or Zod models instead?

Yes. The Pydantic tab writes Pydantic v2 classes with `extra="forbid"`, and the Zod tab writes a `z.object(...).strict()` schema. Both match the JSON Schema, so you can validate the reply in Python or TypeScript.

## Go deeper

-   [Glossary: structured output](https://broadrouter.com/glossary/structured-output/)
-   [Use the OpenAI Python SDK with BroadNet](https://broadrouter.com/guides/openai-python-sdk/)
-   [Use the OpenAI Node SDK with BroadNet](https://broadrouter.com/guides/openai-node-sdk/)
-   [API request builder](https://broadrouter.com/tools/api-request-builder/)
-   [GLM 5.3: model page](https://broadrouter.com/models/glm-5.3/)

## More free tools

-   [**LLM API cost calculator**Price a workload on every model at once, with cache hits, reasoning and a flat-plan check.](https://broadrouter.com/tools/llm-api-cost-calculator/)
-   [**Speech-to-text cost calculator**Hours, calls or voice notes to a monthly transcription bill, against your current provider.](https://broadrouter.com/tools/speech-to-text-cost-calculator/)
-   [**LLM token counter**Exact token counts with each model's real tokenizer, with a token view and cost.](https://broadrouter.com/tools/token-counter/)
-   [**Arabic token counter**Arabic vs English token counts per tokenizer: the "Arabic tax" in tokens and money.](https://broadrouter.com/tools/arabic-token-counter/)
-   [**Tokens to words converter**Tokens ↔ words ↔ characters ↔ pages, by language and content type.](https://broadrouter.com/tools/tokens-to-words/)
-   [**Context window calculator**Will it fit? Window used per model, room left for output, cost to send.](https://broadrouter.com/tools/context-window-calculator/)
-   [**Flat-rate vs per-token LLM cost calculator**Break-even between an unlimited plan and paying per token, per agent.](https://broadrouter.com/tools/flat-rate-vs-per-token-calculator/)
-   [**Prompt caching savings calculator**Bill with and without caching, by prefix share and hit rate.](https://broadrouter.com/tools/prompt-caching-calculator/)
-   [**Image token calculator**Tokens and cost per image under each model's documented rule. Drop an image; nothing is uploaded.](https://broadrouter.com/tools/image-token-calculator/)
-   [**Self-hosting vs API cost calculator**GPU rental against your current API and BroadNet per-token and flat-plan prices: cost per 1M tokens and break-even volume.](https://broadrouter.com/tools/self-hosting-vs-api-calculator/)
-   [**Embedding cost calculator**Index, update and query costs for a corpus at OpenAI, Google, Voyage, Mistral and Jina list prices.](https://broadrouter.com/tools/embedding-cost-calculator/)
-   [**LLM rate limit and concurrency calculator**Which limit binds first: RPM, TPM or concurrency, with Little's law.](https://broadrouter.com/tools/llm-rate-limit-calculator/)
-   [**OpenAI-compatible API request builder**One request, copied as curl, Python, Node or the OpenAI SDKs.](https://broadrouter.com/tools/api-request-builder/)
-   [**Audio file splitter for speech-to-text limits**Chunk count, overlap and copy-ready ffmpeg commands to fit a transcription file-size limit.](https://broadrouter.com/tools/audio-splitter-ffmpeg/)
-   [**Agent run cost estimator**Context growth per step, total tokens and cost of one agent run, with a DeepSeek session comparison.](https://broadrouter.com/tools/agent-run-cost-estimator/)
-   [**OpenAI to BroadNet migration helper**Paste OpenAI SDK code; get base URL, key and model edits, a diff and the checks that remain.](https://broadrouter.com/tools/openai-to-broadnet-migration/)
-   [**Arabic text normalizer**Tashkeel, tatweel, alef, ya, ta marbuta, digits and invisible characters, with a matching Python function.](https://broadrouter.com/tools/arabic-text-normalizer/)
-   [**RAG chunking calculator**Chunks, embedding tokens, input per query, context check and monthly LLM cost for a RAG pipeline.](https://broadrouter.com/tools/rag-chunking-calculator/)
-   [**max\_tokens calculator for reasoning models**Answer length + reasoning budget + margin = a max\_tokens that does not cut the answer off.](https://broadrouter.com/tools/reasoning-token-budget/)
-   [**LLM batch job planner**Run time, binding limit, cost per model and the flat sessions needed to finish a big job by a deadline.](https://broadrouter.com/tools/llm-batch-job-planner/)
-   [**LLM JSON output validator**Parse errors by line and column, safe repairs, cut-off detection and JSON Schema checks for model output.](https://broadrouter.com/tools/llm-json-output-validator/)
-   [**Prompt token diff**Two prompt versions side by side: changed lines, exact token delta and the monthly cost difference.](https://broadrouter.com/tools/prompt-token-diff/)

Try it on your real workload. New accounts start with $5 of credit for Gemma and transcription. DeepSeek, GLM and Qwen3.8 need a top-up.

[Get started](https://inference.broadnet.ai/account/?utm_source=broadrouter&utm_medium=referral&utm_campaign=tools-json-schema-generator&utm_content=page-cta) ·

**Sources**

-   [BroadNet Inference machine-readable prices (pricing.json)](https://inference.broadnet.ai/pricing.json?utm_source=broadrouter&utm_medium=referral&utm_campaign=tools-json-schema-generator&utm_content=sources)
-   [OpenAI structured outputs guide, supported schemas, checked 2026-11-14](https://developers.openai.com/api/docs/guides/structured-outputs)
-   [BroadNet Inference API reference](https://inference.broadnet.ai/docs?utm_source=broadrouter&utm_medium=referral&utm_campaign=tools-json-schema-generator&utm_content=sources)
